I have a situation in winforms, there is a validation in datetimeControl.Leave method which results in messagebox. User selects a invalid date and then clicks on a different tab. now the Leave event is executing and messagebox is being displayed in a new tab. After clicking OK, UI hangs up.
I am not allowed to move validation to DateTimeControl.ValueChanged event.
When i used BeginInvoke, i don't get any hangups.
this.BeginInvoke((Action)(() =>
_serviceProvider.GetService<IShell>().ShowMessageBox(Properties.Resources.NoAvailableReceiptsTitle,
string.Format(Properties.Resources.NoAvailableReceiptsMsgWithDepositDate,
_document.GroupDeposit.UserPostedOn.ToShortDateString(),
((ITrustAccountInfo)_trustAccountCombo.Value).Code),
null,
MessageBoxIcon.Information,
MessageBoxButtons.OK)
));
however our application is very huge and very complex and i was asked to use InvokeRequired and Invoke. But InvokeRequired is always false and handle is always created.
if (this.IsHandleCreated)
{
if (!this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() =>
_serviceProvider.GetService<IShell>().ShowMessageBox(Properties.Resources.NoAvailableReceiptsTitle,
string.Format(Properties.Resources.NoAvailableReceiptsMsgWithDepositDate,
_document.GroupDeposit.UserPostedOn.ToShortDateString(),
((ITrustAccountInfo)_trustAccountCombo.Value).Code),
null,
MessageBoxIcon.Information,
MessageBoxButtons.OK)
));
}
}
i tried to check if the control isDisposed. but that is false. I checked all the related posts.
Invoke or BeginInvoke cannot be called on a control until the window handle has been created
I am puzzled that BeginInvoke doesn't result in hangup but Invoke does. Today is my Day4 on this problem and i am a new hire here. I would appreciate any hints. Thank you.