DynamicInvoke and BeginInvoke

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi. I'd like to know more about the diference between the DynamicInvoke and
the BeginInvoke methods. It seems that BeginInvoke uses the DynamicInvoke
method internally, but I'm not sure about this. So what's the difference in
terms of performance? What happens if I call BeginInvoke and do not call
EndInvoke? Is there a situation when one is better than the other?

Thanks
 
BeginInvoke is used to execute the delegate on a threadpool thread.
DynamicInvoke, IIRC, is just a convenient way of invoking a delegate
without knowings its type. You could do, for example,
Delegate d = new SomeDelegate(SomeMethod);
d.DynamicInvoke(new object[] {param1, param2})

instead of
SomeDelegate d = new SomeDelegate(SomeMethod);
d(param1, param2);

DynamicInvoke is useful when you don't know the exact signatures of the
methods in advance.

Every call to BeginInvoke must be accompanied by EndInvoke. You'll leak
resources if you don't. What's more, if the method threw an exception,
EndInvoke will cause it to be rethrown, so if you don't call EndInvoke,
you'll never know if the method executed successfully.

Regards
Senthil
 
Only one more question: the BeginInvoke and the DynamicInvoke methods use the
ThreadPool or the DynamicInvoke executes the method on the same thread?

Ricardo
 
Back
Top