On Fri, 11 Jan 2008 09:49:31 -0800, roundcrisis <ro*********@gmail.com>
wrote:
[...]
i read somewhere that i should use begin invoke over invoke
does this make sense and if so why
You can use either. Invoke() is useful if you need or want to wait on the
return value for the delegate being executed, or if you want to take
advantage of the inherent synchronization Invoke() provides.
BeginInvoke() is useful if you don't care about the result of the
invocation and want the invoking thread to continue with its processing.
But using BeginInvoke() you will have to ensure synchronization between
any data structures used both in the invoked method and the invoking
thread, if any.
and where should i use end invoke?
For Control.BeginInvoke() _only_, the unofficial information is that
calling Control.EndInvoke() is not required. For all other examples of a
BeginXXX() method, you must call the corresponding EndXXX() method after
the asynchronous operation has completed.
Using Control.BeginInvoke(), you might still want to call
Control.EndInvoke() if you want to retrieve the return value from the
method that was invoked. In that case, you can call EndInvoke() whenever
you want, but be aware that if the invoked method hasn't completed yet,
EndInvoke() will wait and not return until the invoked method is done.
Pete