I'm thinking the reason is because the data is coming from a worker thread within the SqlDependency class and I have to create some means of marshalling it into the main (gui) thread.
Below is my first whack at the event handler but for some reason it does not work. That is I still have to mash a refresh button. Can anyone offer a suggestion
void ExcepNotification_NewExceptionNotification(DataSet NewDataSet)
{
// This event will occur on a thread pool thread.
// Updating the UI from a worker thread is not permitted.
// The following code checks to see if it is safe to
// update the UI.
ISynchronizeInvoke i = (ISynchronizeInvoke)this;
// If InvokeRequired returns True, the code
// is executing on a worker thread.
if (i.InvokeRequired)
{
// Create a delegate to perform the thread switch.
NewExceptionNotificationHandler tempDelegate = new NewExceptionNotificationHandler(ExcepNotification_NewExceptionNotification);
object[] args = { NewDataSet };
// Marshal the data from the worker thread
// to the UI thread.
i.BeginInvoke(tempDelegate, args);
return;
}
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = NewDataSet;
dataGridView1.DataMember = NewDataSet.Tables[0].ToString();
}