Click here to Skip to main content
13,287,856 members (37,657 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.

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
These methods have nothing to do with ADO.NET, but of course you can use ADO.NET with it. The question is: why?

1 solution

Rate this: bad
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[^].


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171207.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2017
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