Skip to main content

Posts

Showing posts with the label Multithreading

...

....

C# - Generic Method to safely perform Cross-Thread Invoke [Beginner]

Have you ever written a multi-threaded application in .NET? If you have, chances are, you think that making thread-safe calls to update your UI is, well, really annoying and verbose at best. The issue is that every time you are doing work in a thread other than your UI thread, and then need to update the UI from said thread, you need to create a delegate pattern in order to do so without getting an InvalidOperationException. Threads are nice when you need to do stuff in the background without causing your application to hang. Often you want to show the progress of the load that is being handled. In many occasions, that's a progressbar but in some you want to show in detail what is being done. In the first situation where it is only needed to update a progress bar, a backgroundworker can be used. The background worker sends thread safe events. In that event, you can update your progress bar. In the other situations where you want to show more information of w