G
gilles27
I have an exception handling procedure which displays an error message
to the user. This is done by creating an instance of the custom form
ErrorDisplay and showing that instance as a modal dialog, parented to
the main MDI window. The code is as follows.
Private Shared Sub DisplayExceptionMessage(ByVal ToDisplay As String)
Dim frmError As New ErrorDisplay(ToDisplay)
frmError.StartPosition = FormStartPosition.CenterScreen
If frmError.ShowDialog(MdiParent) = DialogResult.No Then
Application.Exit()
End If
End Sub
This procedure normally runs on the main thread, however I have
recently introduced multithreading to the application and am now
finding that it will sometimes run on one of the worker threads I have
created.
The problem comes when showing the error form as its behaviour is not
exactly the same as when the procedure runs from the main thread. I
believe this is because the MdiParent variable, which is a reference to
the app's MDI window, was created on the main thread and frmError on
the worker thread. I probably need to use the Control.Invoke method
here but can't quite see how. This theory is backed up by the fact that
MdiParent.InvokeRequired returns true when running on the worker
thread.
Any suggestions would be gratefully received.
Thanks,
Ross
to the user. This is done by creating an instance of the custom form
ErrorDisplay and showing that instance as a modal dialog, parented to
the main MDI window. The code is as follows.
Private Shared Sub DisplayExceptionMessage(ByVal ToDisplay As String)
Dim frmError As New ErrorDisplay(ToDisplay)
frmError.StartPosition = FormStartPosition.CenterScreen
If frmError.ShowDialog(MdiParent) = DialogResult.No Then
Application.Exit()
End If
End Sub
This procedure normally runs on the main thread, however I have
recently introduced multithreading to the application and am now
finding that it will sometimes run on one of the worker threads I have
created.
The problem comes when showing the error form as its behaviour is not
exactly the same as when the procedure runs from the main thread. I
believe this is because the MdiParent variable, which is a reference to
the app's MDI window, was created on the main thread and frmError on
the worker thread. I probably need to use the Control.Invoke method
here but can't quite see how. This theory is backed up by the fact that
MdiParent.InvokeRequired returns true when running on the worker
thread.
Any suggestions would be gratefully received.
Thanks,
Ross