Event DataTable issue with Timer

  • Thread starter Thread starter Anders
  • Start date Start date
A

Anders

Hi again,

I have two classes Form1 and GenData. Form1 creates an instance of genData.

genData populates a Datatable and then sends it to Form1 using the event
seen below:.

private void updateDatagrid(object sender, DataTable dt)
{
if ( dataGrid1.InvokeRequired )
{
dataGrid1.Invoke(new DataGridEventHandler(this.updateDatagrid));
}
else
{
dataGrid1.DataSource = dt;
}

}

The issue is, that when this event is called from a System.Timers.Timer
event (in genData) the datagrid is not filled. However, when I call the
event manually it works fine. As you can see above I tried to decipher the
inner workings of Invoke but it hasnt helped.

This is a windows app .Net 1.1 framework.

I have been strugling with this strange issue all day, I hope someone can
help.
Thanks,
Anders
 
Hi, I have somehow solved the problem. From From1 i refer the genData and
set the Timer to synchronize with the Form1 object:

genData.aTimer.SynchronizingObject = this;

If anyone has a better solution then please inform me.
Cheers,
Anders
 
Back
Top