Hello everyone. I am dealing with a very multithreaded environment at the moment, and as you may expect, this involves the complicated subject of properly aborting a thread.
Now I know that calling .Abort() on it is not the way to go, so that is not what I do. Instead I have a variable declared that states whether a thread should continue or not.
When aborting, it's a simple process of changing this state and calling Join() on the Thread.
Example, this is in an Image frame storing class that also handles the animation:
To abort:Code:Private Sub UpdateAnimation() Try While Not disposedValue Dim now As Date = Date.Now If now.Subtract(Me.m_lastFrameChange).TotalMilliseconds >= Me.m_frameDelays(Me.m_frameIndex) Then Me.m_lastFrameChange = now If Me.m_frameIndex = Me.m_frameTotal - 1 Then Me.CurrentFrame = 0 Else Me.CurrentFrame += 1 End If End If Threading.Thread.Sleep(50) End While Catch ex As System.Threading.ThreadInterruptedException End Try End Sub
Now what is the issue? The Interrupt. In my IDE it spams a pointless message despite it being handled in the Try-Catch:Code:Me.disposedValue = True ' ... some other disposing logic ... Me.m_animateThread.Interrupt() Me.m_animateThread.Join()
Is there any way to COMPLETELY hide this exception from the debugger?Code:A first chance exception of type 'System.Threading.ThreadInterruptedException' occurred in mscorlib.dll A first chance exception of type 'System.Threading.ThreadInterruptedException' occurred in mscorlib.dll A first chance exception of type 'System.Threading.ThreadInterruptedException' occurred in mscorlib.dll A first chance exception of type 'System.Threading.ThreadInterruptedException' occurred in mscorlib.dll
It heavily spams my IDE and masks any legitimate runtime exceptions or debugging information to be shown.
I've run into the same issue with invoking on controls where the control is disposed...it forced me to do complicated event handling and SyncLocking to abort whatever thread from invoking things.
In this case, however, the interrupt is needed to avoid wasting 50ms of a thread waiting period. The message forces me not to do it though...
An alternative way of interrupting a Wait that does not cause an exception logged is fine, too.




Reply With Quote
