SafeInvoke method is a simple wrapper around Control.Invoke and just like this .NET method, it requires the Control to actually be fully initialized before it can be used (because it actually uses the Control's message queue to invoke the delegate).
An enhanced version of SafeInvoke should solve this problem:
C#:
private void SafeInvoke(Delegate method, params object[] args)
{
try
{
if (!InvokeRequired)
method.DynamicInvoke(args);
else if (!IsDisposed)
Invoke(method, args);
}
catch (ObjectDisposedException)
{
}
}
VB.NET:
Private Sub SafeInvoke(ByVal method As [Delegate], ByVal args() As Object)
Try
If Not InvokeRequired Then
method.DynamicInvoke(args)
ElseIf Not IsDisposed Then
Invoke(method, args)
End If
Catch x As ObjectDisposedException
End Try
End Sub
The same problem with Control.Invoke method was discussed in microsoft.public.dotnet.framework.windowsforms newsgroup, check it out if you are interested in more information.