Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ADO.NET
my application needs to be notified when any changes are made in the sql server database and the data in the datagridview in my windows form application needs to show the current rows present in the table also notifying me that a change has been done in the database.example in my book has the code to perform the desired task but where i am confused is where the application uses the datagridview1.Invoke() method.
 
EXAMPLE:-
dataGridView1.Invoke((datagrid)delegate(DataTable table) { dataGridView1.DataSource = table; }, dt);
 
datagrid is the name of my delegate that i have declared earlier and dt has the refrence to the DataTable object.
 
can someone explain me in details what's happening in the datagridview1.Invoke() method.
Posted 3-Feb-13 22:50pm
rtz87865
Comments
Sergey Alexandrovich Kryukov at 4-Feb-13 4:01am
   
These methods have nothing to do with ADO.NET, but of course you can use ADO.NET with it. The question is: why?
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The methods System.Windows.Forms.Control.Invoke and System.Windows.Forms.Control.BeginInvoke take the delegate instance passed, as well as the array of parameters needed to pass to delegate instance call, and queue this data in some queue read by the UI thread. This way, the call is done be a UI thread. This mechanism is only needed when you call invocation methods from some thread other then the UI thread. (In fact, it can also be used as a trick to modify order of event handling, but should be used with great care.)
 
As you say no word about threads, it may mean that you are using invocation in vain. Please check it up.
 
For explanation in some more detail, please see my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].
 
You can also get a good idea of how it is internally implemented, if you read my short article where I introduce similar mechanism for non-UI (custom, user-written) thread. Please see:
Simple Blocking Queue for Thread Communication and Inter-thread Invocation[^].
 
—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 265
1 Sergey Alexandrovich Kryukov 202
2 George Jonsson 185
3 King Fisher 185
4 CPallini 155
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100