views:

16

answers:

2

I have an application that will upload files from my client to a web server using HttpWebRequest (with the function suggested here: http://stackoverflow.com/questions/566462/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?

+1  A: 

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.

Laurens Ruijtenberg
+2  A: 

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.

GenericTypeTea