Simple Multithreading example in .NET and WPF

After lots of googling, trying to figure out how to multithread properly in .NET and modify a WPF GUI from another thread, I’ve finally figured a lot of stuff out.  I have created a simple multithreading example project in Visual C# 2008 Express.

WPF Multithreading demo app

You can download the project here, but since I know most people just want to get some quick answers, here’s a few code snippets:

This following is a member method of a WPF Window.

 WPF Dispatcher Example

The following is an example of a member method of a WPF window that runs itself in a separate thread. 
.NET multithreading example code

The project file contains more examples, including handling multithreaded events, how to create custom delegates, getting thread states, and intelligently killing threads when the program shuts down.

7 thoughts on “Simple Multithreading example in .NET and WPF

  1. Nice work David.

    Multi-threaded programming is yummy! Omnomnom!

    You now need to find something to program using threads on your multi-core, hyperthreading machine…

    Mr. R

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>