I have a form being displayed by a static method.
This static method calls ShowDialog on 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 of the dialog to wait up to one second before it shows, so it will only display if a lock on a record cannot be achieved after 1 second. It will happily drop out before one second if a lock is obtained before 1 second, setting its DialogResult to OK.
All functionality works fine except the hiding of the Dialog box for 1 second. All 'Visible = false' calls are ignored, and I can kind of understand why they would do that. The problem with this is that a false 'record is locked' will flash up for a sub second every time the form is used and a lock can be obtained without an issue.
I can figure out a few hacky ways to delay the visibility of the dialog box
- Set Opacity to 0% - this does not work for Remote Desktop Connections
- Have the form only be initialized by the static method once the 1 second has elapsed. This is promising, but requires a lot of repeated static vs non static code to handle the setup and disposal of the lock, and still feels a bit hacky.
Is it possible to limit the display of a Modal Dialog called through ShowDialog? I am reluctantly happy to PInvoke at this point (though I do want to limit non-64bit code for future requirements)
EDIT
By moving my acquire lock code to the form's constructor instead of Load, I can keep the locking code in one place, and just wait while the form's lock status is in a Waiting state before calling ShowDialog. Still feels dirty, but the cleanest method so far