Learn how to Make Money Online | Free Tech Magazines
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Articles / Source Code > Programming > C#

Discuss / Comment Copy HTML to Clipboard  Copy BBCode to Clipboard  Add to del.icio.us  Add to Google  Digg it  Add to Yahoo !  Add to Windows Live  Add to Facebook  Add to StumbleUpon 
 
Bookmarks Article Tools Search this Article Display Modes

Invoke and BeginInvoke of control and delegates

By shabbir shabbir is offline

On 23rd February, 2007
Cool Invoke and BeginInvoke of control and delegates

ADVERTISEMENT
Show Printable Version Email this Page Subscription Add to Favorites Copy Invoke and BeginInvoke of control and delegates link

Author

shabbir ( Go4Expert Founder )

Shabbir is a developer in the field of Applications, web as well as database designing and is devoted to the optimization and usability of the code. He maintains Programming forum and is a C++ addict.


All articles By shabbir

Recent Articles

Similar Articles

  • Oops, No Similar Articles found for Invoke and BeginInvoke of control and delegates but you can check out the Recent Articles.
  • Also see more articles by shabbir.
Delegate.Invoke

Delegate.Invoke is used to execute a delegate on the current thread. A delegate is just a reference to a function or method, and Delegate.Invoke is the mechanism to call this function or method (similar to a normal function call).

Delegate.BeginInvoke

Delegate.BeginInvoke is used to execute a delegate asynchronously, that is, on a separate thread. That means that you can start an operation which won't block your current thread, it will be executed on it's own thread. Delegate.BeginInvoke the operation will be performed "in the background", that is, on a separate thread. Note that you need to call EndInvoke at some time after BeginInvoke to avoid resource leaks.

As its a seperate thread you must not update any property or call any method of a Windows Forms user that potentially update the UI. If you want to update a progress bar, fill a list, or do somehting similar while the operation is performed, you have to use a different mechanism: Control.Invoke or Control.BeginInvoke.

Control.Invoke

Control.Invoke is used to execute a delegate on the UI thread of that control. If you have a delegate which updates the user interface, you can call Control.Invoke from your other thread to execute the update operation on the UI thread.

Control.BeginInvoke

Control.BeginInvoke does the same, but in an asynchronous way. This means that, while Control.Invoke waits until the UI thread has finished executing the delegate, Control.BeginInvoke returns immediately.

Notes to remember:

Control.Invoke, Control.BeginInvoke, and Control.InvokeRequired are exceptions and can use these from other threads than the UI thread.
Old 05-24-2009, 04:10 PM   #2
varunjoshi
Newbie Member
 
Join Date: May 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
varunjoshi is on a distinguished road

Re: Invoke and BeginInvoke of control and delegates


If Control.BeginInvoke is asynchronus then does it executes on separate thread?
If yes then in that case we should get some exception if we try to access some UI element.
varunjoshi is offline   Reply With Quote
Discuss / Comment Copy HTML to Clipboard  Copy BBCode to Clipboard  Add to del.icio.us  Add to Google  Digg it  Add to Yahoo !  Add to Windows Live  Add to Facebook  Add to StumbleUpon 


Currently Active Users Reading This Article: 1 (0 members and 1 guests)
 
Article Tools Search this Article
Search this Article:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

 

All times are GMT +5.5. The time now is 05:11 AM.