Dynamic invoke and sleep thread

212 Views Asked by At

I've a question about dynamic invoke and threads. Let's suppose that I have a main thread that in some point shows a dialog.

public void showDialog()
{
    lock(mutexObject)
    {
        flagDialogShowing = true;
        showMssgDialog(properties...);
        flagDialogShowing = false;
    }
}

When I show that Dialog my mainThread get the mutexObject and stops until user click accept button. So my main thread is sleeping. If the user don't push the button and we wait an event is raised in another thread. That events use a dynamicInvoke to call the previous function. In that case mainThread getUp and if I don't use the flagDialog it will be shown a second dialog. It's this correct? What dynamicInvoke does if the thread is not sleeping? it will wait until mainThread is stopped? What happens if I close the two dialogs how it knows where to continue the execution? It stacks different callstacks and know how to recover the old context?

Thank you very much.

1

There are 1 best solutions below

0
On

Instead of that flag, you could have your other thread do a

if(Monitor.TryEnter(mutexObject))
    raiseEvent(...);
    Monitor.Exit(mutexObject);

if you want it to not wait for your current Dialog, or a complete

lock(mutexObject)
{
    raiseEvent();
}

if you want it to wait.

I'm not too long into C# myself, so I won't try to answer those questions there, don't wanna spread guesses as knowledge :)