latest tweets:

Jump to content.

Simple Multithreading example in .NET and WPF

March 28th, 2010

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 comments

  1. Mr. R posted on March 29, 2010:

    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

  2. David McGrath posted on March 29, 2010:

    haha, thanks. I use multithreading in my two main projects, Arcadia and (soon to be renamed) Roomie

  3. Steve posted on March 30, 2010:

    Dispatcher.CheckAccess() is a better way so you don’t have to compare the thread yourself :)

  4. David McGrath posted on March 30, 2010:

    Thanks, Steve! Unfortunately I don’t have any formal C# training, since most classes at my university is either Java or C/C++. I appreciate your insight.

  5. Chaiwatn posted on April 7, 2012:

    Thank

  6. Raz posted on April 13, 2012:

    hi David
    after i download it and try to open with winzip
    it fails. can you send me it to zbalbel@gmail.com

    thank you

  7. David McGrath posted on May 21, 2012:

    Oops, Sorry, Raz. My download service was broken, and I didn’t notice! It’s fixed now.

RSS feed for comments on this post.

Leave a comment

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



Read more

« »