Please see the comment by Mark and my comment to the question.
You just need to understand the difference between
Invoke
and
BeginInvoke
operations and infer the conclusion by yourself because only you have the whole code. A change from one method to another may change the order of calls.
By the way, you can observe the order of execution it by logging some information form different place of your code using the class
System.Diagnostics.EventLog
http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx[
^]. If you use the Debugger, you can introduce time delay which can change the picture (
race condition, see
http://en.wikipedia.org/wiki/Race_condition[
^]).
The delegate used in the call to
Invoke
or
BeginInvoke
from any thread other then the thread of you UI is never called on a calling thread. Instead, it is dispatched by adding it to an event queue of the UI thread. The UI retrieve the delegate and parameters required to make a call and calls it on the UI thread. If you use
BeginInvoke
, the method returns right after the delegate and call parameters are queued, but
Invoke
is blocking the called until the delegate is actually called on the UI thread. This different behaviors can cause different order of some operations.
You can analyze your code and/or use
EventLog
to figure out what happens.
See also my past solutions:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
—SA