Universal answer (with explanation):
BeginInvoke
is function that send a message 'this function should be executed in different thread' and then directly leaves to continue execution in current thread.
The function is executed at a later time, when the target thread has 'free time' (messages posted before are processed).
When you need the result of the function, use Invoke
. The Invoke
function is 'slower', or better to say it blocks current thread until the executed function finishes. (I newer really tested this in C#, but it s possible, that the Invoke
function is prioritized; e.g. when you call BeginInvoke
and directly after it Invoke
to the same thread, the function from Invoke
will probably be executed before the function from BeginInvoke
.)
Use this alternative when you need the function to be executed before the next instruction are processed (when you need the result of the invoked function).
Simple (tl;dr): When you need to need to only set a value (e.g. set text of edit box), use BeginInvoke
, but when you need a result (e.g. get text from edit box) use always Invoke
.
In your case you need the result (bitmap to be drawn) therefore you need to wait for the function to end. (There are also other possible options, but in this case the simple way is the better way.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…