Synclock a section of code while waiting for ShowDialog to return
- by clawson
I'm having trouble working out how to lock my application out of a section of code while it waits for a response from an external program.
I've used Synclock on a section of code with the Me object in the expression. In this Synclock I call an overridden ShowDialog method of a dialog box, which has a timeout parameter, but does return the value from the underlying ShowDialog function call ,once the timer is setup. Works like this.
SyncLock Me
Dim frmDlgWithTimeout As New frmDlgWithTimeout ' dialog box with overridden ShowDialog '
Dim res As DialogResult = frmDlgWithTimeout.ShowDialog(10 * 1000) ' 10 sec timeout '
End SyncLock
Now, external programs may raise events that bring my application to this Synclock but it doesn't prevent it from entering it, even though the ShowDialog function hasn't returned a value (and hence what I thought would keep the section of code locked).
There is only one instance of the object that is used for lock in the program.
Your help is greatly appreciated.