Synclock a section of code while waiting for ShowDialog to return

Posted by clawson on Stack Overflow See other posts from Stack Overflow or by clawson
Published on 2010-06-01T07:52:15Z Indexed on 2010/06/01 7:53 UTC
Read the original article Hit count: 285

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.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about vb.net