Updating dataset using thread ... CPU taking lot of time..Need Help

  • Thread starter Thread starter batista
  • Start date Start date
B

batista

Hello all,

I have a third praty grid control...named C1grid. Im using it in one of
my apps..
Now, I have bind this grid to a custom dataset class named
"DataViewEx".
The code of the class is below...

Now what happens is that im updating this dataviewex class from a
separate thread.....
And then the grid is updated using invoke method.

But here comes the problem....
This app is real time...and there is lots of data coming at a very fast
rate....
And when the updation of dataviewex class takes place the cpu takes a
lot of time.....
And in certain cases it even hangs.....taking almost 100 CPU time...

So my question is that

1) Is it happening because of invoke...Or what is the problem....Why is
the CPU hanigng...
Whats causing the CPU to take such a long time.....

Please any suggestions....

Thanks,
Cheers..

Bye.

The code of the class is below....



using System;
using System.Data;
using System.ComponentModel;

namespace AAA
{
public class DataViewEx : DataView
{
private C1FlexGrid m_fgrdDataGrid;

public DataViewEx(C1FlexGrid fgrdDataGrid) : base()
{
m_fgrdDataGrid = fgrdDataGrid;
}

private delegate void OnListChangedDelegate(ListChangedEventArgs e);

protected override void OnListChanged(ListChangedEventArgs e)
{
if ( m_fgrdDataGrid != null && m_fgrdDataGrid.InvokeRequired )
{
m_fgrdDataGrid.Invoke( new OnListChangedDelegate( OnListChanged ),
new object[]{e} );
}
else
base.OnListChanged(e);
}

private delegate void IndexListChangedDelegate(object sender,
ListChangedEventArgs e);

protected override void IndexListChanged(object sender,
ListChangedEventArgs e)
{
if ( m_fgrdDataGrid != null && m_fgrdDataGrid.InvokeRequired )
{
m_fgrdDataGrid.Invoke( new IndexListChangedDelegate(
IndexListChanged ), new object[]{ sender, e } );
}
else
base.IndexListChanged( sender, e );
}
}
}
 
Hi,

You could try replacing "Invoke" with "BeginInvoke".

BeginInvoke is usually better, because it allows the backgroundthread to
continue its work instead of waiting for the UI thread to perform the update.

There is lots of data coming very fast, is that continuously, or now and then?
If is it continuously, then maybe it would be better to just update the
screen every 200 milliseconds, or faster or slower (I don't know the
requirements).

If it is not continuously, you could refdresh the screen with a small delay,
thus resulting in fewer updates of the screen. I'll explain this a little
better:
If let's say every 5 seconds you have 20 parts of new data with 20 ms
interval, then 5 seconds "silence", and again multiple updates. If, instead
of updating the screen every time new data arrives, you start a timer
(interval 100 ms, for example), and when the timer elapses, then start the
update. This could result in fewer updates, every time showing multiple
parts of your new data.

These are techniques I have used in the past to improve the user experience
when fast screen updates where causing performance problems.

Hope this helps,

Joris


batista said:
Hello all,

I have a third praty grid control...named C1grid. Im using it in one of
my apps..
Now, I have bind this grid to a custom dataset class named
"DataViewEx".
The code of the class is below...

Now what happens is that im updating this dataviewex class from a
separate thread.....
And then the grid is updated using invoke method.

But here comes the problem....
This app is real time...and there is lots of data coming at a very fast
rate....
And when the updation of dataviewex class takes place the cpu takes a
lot of time.....
And in certain cases it even hangs.....taking almost 100 CPU time...

So my question is that

1) Is it happening because of invoke...Or what is the problem....Why is
the CPU hanigng...
Whats causing the CPU to take such a long time.....

Please any suggestions....

Thanks,
Cheers..

Bye.

The code of the class is below....



using System;
using System.Data;
using System.ComponentModel;

namespace AAA
{
public class DataViewEx : DataView
{
private C1FlexGrid m_fgrdDataGrid;

public DataViewEx(C1FlexGrid fgrdDataGrid) : base()
{
m_fgrdDataGrid = fgrdDataGrid;
}

private delegate void OnListChangedDelegate(ListChangedEventArgs e);

protected override void OnListChanged(ListChangedEventArgs e)
{
if ( m_fgrdDataGrid != null && m_fgrdDataGrid.InvokeRequired )
{
m_fgrdDataGrid.Invoke( new OnListChangedDelegate( OnListChanged ),
new object[]{e} );
}
else
base.OnListChanged(e);
}

private delegate void IndexListChangedDelegate(object sender,
ListChangedEventArgs e);

protected override void IndexListChanged(object sender,
ListChangedEventArgs e)
{
if ( m_fgrdDataGrid != null && m_fgrdDataGrid.InvokeRequired )
{
m_fgrdDataGrid.Invoke( new IndexListChangedDelegate(
IndexListChanged ), new object[]{ sender, e } );
}
else
base.IndexListChanged( sender, e );
}
}
}
 
Back
Top