WPF, STA and WaitHandle.WaitAll

by mheydt 29. December 2007 16:57 >
I can across a curious issue tonight when doing some multithreading in WPF.  Upon the user pressing a button on the WPF form, I was starting a few threads to accomplish some tasks in parallel, and I wanted to wait for both of those tasks to complete first as I need output from both of them to finalize the process that pressing the button entails.  As usual I spun up a few threads, created a ManualResetEvent for each thread, and called WaitHandle.WaitAll on those handles.  Much to my surprise this through an exception stating that WaitAll cannot be used from an STA thread!

I found this curious.  Technically I don't understand why you can not call this from an STA thread as why can't an STA thread through that method monitor several other threads through those handles?  I don't know.  Anyway, the solution was to spin up another thread as the result of presssing the button that would then start those other threads, and the WaitAll then works fine in that thread as it defaults to MTA.

BTW, this is all because WPF UI's must run in STA, and the event handler for a button press then runs in STA and for all I know you can't change that.

Tags:

.Net | C#

Silverlight tools for VS.NET 2008

by mheydt 27. December 2007 16:55 >
I got around to going back to my silverlight photo viewer project today, and was surprised to find that since upgrading to vs.net 2008 that the tools alpha for silverlight was not compatible. Fortunately, with a little googling I found this upgrade. Same name as the old tools, but a new publish date. It did appear that an uninstall of the non-working tools is needed first.

The error from VS.NET was:

“Package Load Failure

Package ‘Microsoft.VisualStudio.Silverlight.SLPackage, Microsoft.VisualStudio.Silverlight, Version=9.0.0.0,…”

And the link is:

http://www.microsoft.com/downloads/details.aspx?FamilyId=25144C27-6514-4AD4-8BCB-E2E051416E03&displaylang=en

Tags:

.Net | Silverlight

about the author

I'm a .NET, XAML, and iOS polyglot that loves playing with new things and making cool and innovative stuff.  I am also a Mac junkie.

I am Principal Technologist for SunGard Global Services in NYC, in their Advanced Technologies practice, and I work extensively with SunGard's energy and financial customers.

Note the the posting on this blog are my own and do not represent the position, strategies or opinions of SGS.

twitter

I can't stop thinking big!
Sunday 1:08AM via WindowsLive
Just watched Moneyball. That's my pick for best movie this year.
Saturday 3:51PM via WindowsLive
@vincebelpiede: Report: Skype For Windows Phone Beta Imminent http://t.co/KYNjgg1L#mhtnd
Wednesday 8:39AM via Twitter for Mac
@mashable: Kinect Fusion Will Turn Gaming (and More) Into a 3D Fun House - http://t.co/Ihrq2fY2#mhtnd
Wednesday 8:39AM via Twitter for Mac
New Kinect SDK: http://t.co/57MvA5L5 #mhtnd
Wednesday 8:39AM via Twitter for Mac
Follow me on Twitter

recent comments

None

month list