O'Reilly logo

.NET Framework 4.5 Expert Programming Cookbook by A.P. Rajshekhar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling background threads in Windows Forms

In Windows Forms, any thread except the UI thread is considered a background thread. If you want to perform any long operation in a separate thread, then you will have to understand how to handle the background thread. The main aspect of handling a background thread is passing data from the background thread to the UI thread. If you don't handle the data passing in the right way, the controls will not be updated with the correct values. In the worst case, your application will stop responding.

How to do it...

The following recipe will tell you how to handle the background thread in the right way:

  1. Launch Visual Studios 2012. Create a new project of type Windows Forms Application and name it UIThreadHandlingWinForms ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required