473,586 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't WaitHandle.Wait All in an STAThread ?

[the xpost is justifiable, I think]

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

(from the docs for WaitHandle.Wait All)
NotSupportedExc eption The number of objects in waitHandles is greater
than the system permits.
-or-

The current thread is marked with the STAThreadAttrib ute, 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 STAThreadAttrib ute.

Why not? And what could one do about it?

--
Larry Lard
Replies to group please

Feb 16 '06 #1
1 3579

"Larry Lard" <la*******@hotm ail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
| [the xpost is justifiable, I think]
|
| Just now I translated Jon Skeet's WaitHandle.Wait Any / .WaitAll
| (<http://yoda.arachsys.c om/csharp/threads/waithandles.sht ml>) from C#
| into VB.NET, and after the first go I ran into trouble:
|
| (from the docs for WaitHandle.Wait All)
| >>
| NotSupportedExc eption The number of objects in waitHandles is greater
| than the system permits.
| -or-
|
| The current thread is marked with the STAThreadAttrib ute, 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 STAThreadAttrib ute.
|
| 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
"MsgWaitFormult ipleObjects" 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 MsgWaitFormulti pleObjects, 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
2810
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()? Thanks.
1
1385
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
3092
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
4721
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: (from the docs for WaitHandle.WaitAll) >> NotSupportedException The number of objects in waitHandles is greater than the system permits. -or-
0
2423
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 the scenes (by using a spin-wait like mechanism)? What does it mean that Interlocked doesn't switch to kernel mode and WaitHandle does? Do the...
1
2635
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 really a AsyncResult). My question is, when exactly is this WaitHandle signalled - is it: -when the asynchronous call finishes OR -when...
14
7877
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 let that object take care of running them in the background on the machine's free cycles. But I need the program to wait for all the queued pieces...
12
5049
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. OpenFileDialog. I can't declare a main method as STAThread because of XNA framework. Is there any way to declare form or some method in form as...
0
1803
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 Handler", BeginProcessRequest() returns an IAsyncResult whose AsyncWaitHandle getter always returns null. Why is this? Is there some guarantee that...
0
7912
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.