Win form application freeze on HttpWebRequest file post
I have an application that wil开发者_JS百科l upload files from my client to a web server using HttpWebRequest (with the function suggested here: Upload files with HTTPWebrequest (multipart/form-data))
My problem is that when the file (about 10 mb in size) is being posted the whole application freezes (e.g. "application is not responding" when I try to move the window).
Do I need to put the uploading in a separate thread, or is there any other simple way solve this?
Have a look at the BackgroundWorker
class. Your UI will freeze while an operation is ongoing unless you run it in a separate thread.
Using the BackgroundWorker
you can execute your code in the DoWork
event and the UI will remain responsive.
Multithreaded programming is the way to go in this case.
You can create a delegate for a function that will upload the file and use BeginInvoke to execute the function in a seperate thread.
Or you could simply create a new thread by using the Thread class and the build-in .net ThreadPool.
精彩评论