D
Dachshund Digital
Why does Join method call sit there forever? This code works,
including the delegate call, but if the join method is ever called, it
seems the main thread blocks, and it is hung. HELP! This is driving
me nuts!
-----------------------------------------------------------------------------------
Imports System
Imports System.Threading
Imports System.Environment
'
Public Class Form1
'
Private Delegate Sub UpdateDelegate()
Private theThreadOrNot, theUpdateOrNot As Boolean
Private theDelegate As UpdateDelegate
Private theReset As ManualResetEvent
Private theThread As Thread
'
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'
If (theUpdateOrNot) Then
'
theReset.Reset()
theUpdateOrNot = False
Thread.Sleep(250)
End If
theThreadOrNot = True
theReset.Set()
If (theThread Is Nothing) Then
'
Exit Sub
End If
If (theThread.IsAlive) Then
'
theThread.Join()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'
theReset = New ManualResetEvent(False)
theDelegate = New UpdateDelegate(AddressOf _
OnUpdate)
theThread = New Thread(AddressOf _
OnThread)
With theThread
'
.IsBackground = True
.Priority = ThreadPriority.Normal
.Start()
End With
End Sub
Private Sub OnThread()
'
While (Not (theThreadOrNot))
'
If (theReset.WaitOne) Then
'
While (Not theThreadOrNot And theUpdateOrNot)
'
If (Me.InvokeRequired) _
Then
'
Me.Invoke(theDelegate)
End If
End While
End If
End While
End Sub
Private Sub OnUpdate()
'
Me.Label.Text = TickCount.ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If (theUpdateOrNot) Then
'
theReset.Reset()
theUpdateOrNot = False
Else
'
theReset.Set()
theUpdateOrNot = True
End If
End Sub
End Class
including the delegate call, but if the join method is ever called, it
seems the main thread blocks, and it is hung. HELP! This is driving
me nuts!
-----------------------------------------------------------------------------------
Imports System
Imports System.Threading
Imports System.Environment
'
Public Class Form1
'
Private Delegate Sub UpdateDelegate()
Private theThreadOrNot, theUpdateOrNot As Boolean
Private theDelegate As UpdateDelegate
Private theReset As ManualResetEvent
Private theThread As Thread
'
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
'
If (theUpdateOrNot) Then
'
theReset.Reset()
theUpdateOrNot = False
Thread.Sleep(250)
End If
theThreadOrNot = True
theReset.Set()
If (theThread Is Nothing) Then
'
Exit Sub
End If
If (theThread.IsAlive) Then
'
theThread.Join()
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'
theReset = New ManualResetEvent(False)
theDelegate = New UpdateDelegate(AddressOf _
OnUpdate)
theThread = New Thread(AddressOf _
OnThread)
With theThread
'
.IsBackground = True
.Priority = ThreadPriority.Normal
.Start()
End With
End Sub
Private Sub OnThread()
'
While (Not (theThreadOrNot))
'
If (theReset.WaitOne) Then
'
While (Not theThreadOrNot And theUpdateOrNot)
'
If (Me.InvokeRequired) _
Then
'
Me.Invoke(theDelegate)
End If
End While
End If
End While
End Sub
Private Sub OnUpdate()
'
Me.Label.Text = TickCount.ToString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If (theUpdateOrNot) Then
'
theReset.Reset()
theUpdateOrNot = False
Else
'
theReset.Set()
theUpdateOrNot = True
End If
End Sub
End Class