C # Delay Modal Dialog displaying on Load while permission to continue

I have a form displayed by a static method.

This static method calls ShowDialog in the form:

//Static method on LockWaitForm
public static LockDetails Lock(string lockedMessage, object[] params parameters)
{
        using (LockWaitForm form = new LockWaitForm(parameters))
        {
            form._lockedMessage.Text = lockedMessage;

            DialogResult result = form.ShowDialog();

            return new LockDetails (form._lockStatus, form._lock);
        }
 }

What I want is the OnLoad method for the dialog to wait up to one second before it appears, so it will only appear if the write lock cannot be reached after 1 second. It will happily drop out to one second if the lock is received before 1 second by setting its DialogResult to the OK position.

, 1 . "Visible = false" , , . , " " , , .

  • 0% -
  • , , 1 . , , .

, ShowDialog? PInvoke ( -64- )

Load, , ShowDialog. ,

+3
3

, , : LockWaitForm ShowDialog() , ( - ), , 1 , . ShowDialog() (). LockWaitForm, - .

, Visual Studio , , .

+2

, , .

+3

? ? Monitor.TryEnter?

false, , - / .

, .

, Eric J, , . .

, , .

+1

Source: https://habr.com/ru/post/1715374/


All Articles