473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Can't WaitHandle.WaitAll in an STAThread ?

[the xpost is justifiable, I think]

Just now I translated Jon Skeet's WaitHandle.WaitAny / .WaitAll
(<http://yoda.arachsys.com/csharp/threads/waithandles.shtml>) from C#
into VB.NET, and after the first go I ran into trouble:

(from the docs for WaitHandle.WaitAll)
NotSupportedException The number of objects in waitHandles is greater
than the system permits.
-or-

The current thread is marked with the STAThreadAttribute, and
waitHandles contains more than one element.


After digging a bit, I came to the conclusion that VB.NET apps, even
ones that aren't explicitly marked for COM Interop, are STA threaded by
default, so a simple application of the MTAThread attribute to my Main
method fixed the problem.

However, what would I do if I had a real app that *needed* to be
STAThread'd, and I wanted to wait for multiple signals? The docs offer
no justification, just a blunt

Note The WaitAll method is not supported on threads that are marked
with STAThreadAttribute.

Why not? And what could one do about it?

--
Larry Lard
Replies to group please

Feb 16 '06 #1
1 4712

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
| [the xpost is justifiable, I think]
|
| Just now I translated Jon Skeet's WaitHandle.WaitAny / .WaitAll
| (<http://yoda.arachsys.com/csharp/threads/waithandles.shtml>) from C#
| into VB.NET, and after the first go I ran into trouble:
|
| (from the docs for WaitHandle.WaitAll)
| >>
| NotSupportedException The number of objects in waitHandles is greater
| than the system permits.
| -or-
|
| The current thread is marked with the STAThreadAttribute, and
| waitHandles contains more than one element.
| >>
|
| After digging a bit, I came to the conclusion that VB.NET apps, even
| ones that aren't explicitly marked for COM Interop, are STA threaded by
| default, so a simple application of the MTAThread attribute to my Main
| method fixed the problem.
|
| However, what would I do if I had a real app that *needed* to be
| STAThread'd, and I wanted to wait for multiple signals? The docs offer
| no justification, just a blunt
|
| Note The WaitAll method is not supported on threads that are marked
| with STAThreadAttribute.
|
| Why not? And what could one do about it?
|
| --
| Larry Lard
| Replies to group please
|

The reason for this is that "WaitAll" boils down to a call to
"MsgWaitFormultipleObjects" Win32 API with bWaitAll set to TRUE. This would
deadlock when it was allowed to be called from a thread that creates windows
(like an STA thread does). Please check msdn to get more info on the
semantics of MsgWaitFormultipleObjects, especially the remarks are
enlightening.

Willy.


Feb 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
Is there any way to find out: 1. which thread is holding a monitor object? 2. how many Monitor.Enter() has been called on an object? 3. which WaitHandle is signaled after WaitHandle.WaitAny()? ...
1
by: Alberto | last post by:
What's the meaning of the STAThread attribute? Thanks
1
by: Bob Rock | last post by:
Hello, did anyone notice that the WaitHandle class is not abstract as the ..NET SDK documentation says? Bob Rock
2
by: Tom | last post by:
Do we need to put the STAThread attribute on our Sub Main anymore if we are using the 1.1 Framework? See some YEAs and NEAs when searching on Google so thought I would ask here. Tom
1
by: Larry Lard | last post by:
Just now I translated Jon Skeet's WaitHandle.WaitAny / .WaitAll (<http://yoda.arachsys.com/csharp/threads/waithandles.shtml>) from C# into VB.NET, and after the first go I ran into trouble: ...
0
by: Amir Shitrit | last post by:
Hi to all. What is difference between the methods found in the Monitor, Interlocked and WaitHandle classes in terms of performance? Is it true that Monitor.Wait uses the Interlocked class behind...
1
by: Sean | last post by:
I am looking at using delegates to perform an asynchronous call. There will be a callback invoked at the end of the call. The client thread will wait on the WaitHandle from IAsyncResult (which is...
14
by: Dave Booker | last post by:
I'm doing some analysis that is readily broken up into many independent pieces, on a multicore machine. I thought it would be best to just queue like 1000 of these pieces in the ThreadPool, and...
12
by: rafalK | last post by:
Hi All, I have a big problem with STAThread attribute. I'm using XNA framework connected with WinForms. XNA is working in non STAThread. I have a problem with displaying CommonDialog forms e.g....
0
by: UL-Tomten | last post by:
Is the WaitHandle on the IAsyncResult returned from BeginProcessRequest ever used by the HTTP application? The reason I'm asking is that in the MSDN article "How to: Create an Asynchronous HTTP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.