The project has a large file transfer requirements, the user in the Web page to fill out a shared directory under a certain IP, the service side through the fill path to detect files in the shared directory for users to select the files to be transferred,
After the user has checked the corresponding file and clicked Submit, the server began to carry out the file transfer. All the logical processes are in the same background code, the code that passes the file and the other business code are all in the same thread,
Therefore, when the file is too large for the user's page to wait a long time, greatly affect the user experience, so later the process of file transfer in a new thread, in order to improve page response efficiency.
The file transfer process is placed in a new thread using the ThreadPool.QueueUserWorkItem () method, which is invoked as follows:
protected void Page_Load (object sender, EventArgs e) { list<string> filecollection = new list<string> (); Filecollection.add ("\\\\127.0.0.1\\folder\\file1.txt"); Filecollection.add ("\\\\127.0.0.2\\folder\\file2.txt"); Filecollection.add ("\\\\127.0.0.3\\folder\\file3.txt"); String destfolder = "\\\\127.1.1.1\\destfolder"; ThreadPool.QueueUserWorkItem (state = Transmitefile (filecollection, Destfolder));} public void Transmitefile (list<string> filecollection, String destfolder) { //...some logic}
Here to meet ThreadPool, first look at the reference address: line Cheng ThreadPool class and worker thread-< second >
C # Asynchronous thread invocation ThreadPool.QueueUserWorkItem ()