473,718 Members | 2,016 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 3594

"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
2816
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
1388
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
3097
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
4725
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
2430
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 Interlocked methods causes the calling thread to sleep until granted exclusive access to the specified...
1
2639
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 EndInvoke() is called (by the callback)
14
7889
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 to finish before it continues. I tried giving each work item a ManualResetEvent and using...
12
5059
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 STAThread (I think that a method from Form can invoke OpenFileDialog) maybe I'm wrong. Do you know...
0
1813
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 the HTTP application will never wait on a WaitHandle in this situation? What does or doesn't the...
0
8827
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9052
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7985
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6652
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5971
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4481
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4740
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3180
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
2
2550
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.