|
-
Sep 6th, 2010, 01:50 PM
#1
Thread Starter
Lively Member
Apartment threading error
This is a bit of a shift from a previous thread found here: http://www.vbforums.com/showthread.php?t=624198
I'm now trying to use the waithandle class to coordinate thread activity in an app I'm working on.
The following code is a demonstration that manifests an error that I don't understand. Note that what follows is the entire "handwritten" part of the project, written only to demonstrate the exception.
HTML Code:
Imports System.Threading
Public Class Form1
Public WaitThreadEvents(2) As AutoResetEvent
<MTAThread()> _
Sub Main()
Application.Run(New Form1)
End Sub
<MTAThread()> _
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To 2
WaitThreadEvents(i) = New AutoResetEvent(False)
Next
WaitHandle.WaitAll(WaitThreadEvents)
End Sub
End Class
Note the precompiler directive to use multi thread apartment. My understanding is that this is all that's required to allow the use of WaitAll in VB.Net (C# defaults to MTA).
Nevertheless, this dies at WaitHandle.WaitAll(WaitThreadEvents) with a "WaitAll for multiple handles on a STA thread is not supported." exception.
Note that the thread, http://www.vbforums.com/showthread.php?t=552398 which addresses this issue does NOT seem to work for the code I've included. That is my problem.
And ideas?
Thanks.
PS. I'll post or email the entire project on request.
Last edited by jbmckim; Sep 6th, 2010 at 05:40 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|