|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
A solution to "WaitAll for multiple handles on an STA thread is not supported."Seems like a lot of people have trouble with this error. Here's my
solution. I give it to the future. Because I love you. private void WaitAll(WaitHandle[] waitHandles) { if (Thread.CurrentThread.ApartmentState == ApartmentState.STA) { // WaitAll for multiple handles on an STA thread is not supported. // ...so wait on each handle individually. foreach(WaitHandle myWaitHandle in waitHandles) { WaitHandle.WaitAny(new WaitHandle[]{myWaitHandle}); } } else { WaitHandle.WaitAll(waitHandles); } } <isb***@yahoo.com> wrote:
Show quoteHide quote > Seems like a lot of people have trouble with this error. Here's my That seems to change the behaviour entirely though - isn't it actually > solution. I give it to the future. Because I love you. > > private void WaitAll(WaitHandle[] waitHandles) { > if (Thread.CurrentThread.ApartmentState == ApartmentState.STA) { > // WaitAll for multiple handles on an STA thread is not supported. > // ...so wait on each handle individually. > foreach(WaitHandle myWaitHandle in waitHandles) { > WaitHandle.WaitAny(new WaitHandle[]{myWaitHandle}); > } > } > else { > WaitHandle.WaitAll(waitHandles); > } > } waiting for *all* of the handles, just sequentially? -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
> That seems to change the behaviour entirely though - isn't it actually Doh - ignore me. I thought you were trying to mimic Wait*Any* by > waiting for *all* of the handles, just sequentially? calling it multiple times. Why use WaitAny with an array rather than calling WaitOne directly on each handle? That would seem somewhat simpler to me. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
> Jon Skeet [C# MVP] <sk***@pobox.com> wrote: And another point (which I must admit was pointed out to me by Ian > > That seems to change the behaviour entirely though - isn't it actually > > waiting for *all* of the handles, just sequentially? > > Doh - ignore me. I thought you were trying to mimic Wait*Any* by > calling it multiple times. > > Why use WaitAny with an array rather than calling WaitOne directly on > each handle? That would seem somewhat simpler to me. Griffiths - I won't take credit for it) - the whole point of WaitAll is that it's an atomic acquisition, effectively. You unfortunately lose the atomicity in your call, so you could introduce deadlocks which wouldn't otherwise be present. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Myopic thinking. I was fixated on getting a method from WaitHandle to
work. I blame my antibiotics.
.NET Framework Ignores Regional Settings on WinXP
Speed issues with filling a list view How to compare objects why Assembly.LoadFrom() function does'nt load VC++ Project exe file IPAddress sample databases? HOW to solve ... System.Net.WebException: Connection closed programatically how to set the steps involved in enabling the ASP. how do C#.NET load VC++Project exe How does FileSystemWatcher work? |
|||||||||||||||||||||||