Run Code on Another Thread , C#

When we have a certain function that takes a long time for example uploading a file to the server, we don’t want the user wait for that function to finish. We can instead run that function in the background on another thread.

The easiest way of running a function in the background is using ThreadPool.QueueUserWorkItem.

System.Threading.ThreadPool.QueueUserWorkItem(delegate {
   // Write your Code that will run in background here 
}, null);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s