Questions about Form.Invoke and Form.BeginInvoke

S

Stephen Lamb

What type(s) of exceptions will be thrown when calling Form.Invoke when the
handle for the form has yet to be created? MS only states, "If no
appropriate handle can be found, the Invoke method will throw an exception.
Exceptions that are raised during the call will be propagated back to the
caller."
http://msdn.microsoft.com/library/d...ystemwindowsformscontrolclassinvoketopic1.asp

How is a programmer to know if the exception thrown was from running the
delegate or from not having a valid window handle?

Calling Form.Invoke also throws an exception if the form has been disposed.

Why did MS not specify the types of exceptions thrown? They seem to specify
it in all the other cases that I've seen. Are there other cases where they
just state that an exception will be thrown without saying of what type(s)?


Is there any guarantee that if Form.BeginInvoke is called twice from the
same thread on the same form, that the first delegate passed to BeginInvoke
will run first? The docs don't mention this case at all.
 
M

Maqsood Ahmed

If you call Invoke before Form is being shown or after it is disposed a
System.InvalidOperationException is thrown with Message "Cannot call
Invoke or InvokeAsync on a control until the window handle has been
created"

Maqsood Ahmed
Kolachi Advanced Technologies
 
S

Stephen Lamb

Maqsood Ahmed said:
If you call Invoke before Form is being shown or after it is disposed a
System.InvalidOperationException is thrown with Message "Cannot call
Invoke or InvokeAsync on a control until the window handle has been
created"
Thanks for the info. I know that I've gotten at least two differnet
exceptions thrown from calling Invoke.

The problem is that MS does not state what type(s) will be throw. I was
hoping someone might know of some web page where MS actually states the
types or if MS is trying to resolve this issue or if this is a well known
problem with no solution, etc.

What I don't want to do is to rely on experimentation to figure out the
types. If MS doesn't state the types, they can throw whatever types they
want. So on Tuesday, if it is raining in Florida, MS will throw the
EatYourPeasException.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top