GridView Exception: reentrant call to the SetCurrentCellAddressCore function

  • Thread starter Thread starter Martin B
  • Start date Start date
M

Martin B

Hallo to everyone!

Problem:
--------
GridView Exception: reentrant call to the SetCurrentCellAddressCore function

System:
-------
WinXP Professional, english, .NET Framework 2.0 Beta Language C#

Simplified Architecture of my Porgram:

2 Forms:
--------
- MainForm
- DetailForm

2 Threads:
----------
- Main Thread which runs the MainForm //Application.Run(MainForm)
- Telegram Thread //receiving Socket Data for visualization

Scenario:
---------
Telegram Thread receives frequently (2s) socket data which forces the
Main Thread via Callback 'Visualization' to refresh the Data in
the GridView. Within the Callback function 'Visualization' the
Telegram Thread could return immediately, doing his job, by calling
this.Invoke(new VisualDelegate(MainFormVisual)).
'MainFormVisual' wires up the GridView.DataSource with a DataTable,
which is stored offline in memory, as shown in the following lines

1. gvMyGridView.DataSource = null;
2. gvMyGridView.DataSource = BuildActData(); //returning a DataTable

After a undifined and non reproduceable timespan (approx. 20 min)
repating this scenario, the following Exception will be thrown at line 1:
EXCEPTION: Operation is not valid because it results in a reentrant call to
the SetCurrentCellAddressCore function.

Thank you for every advice, bugfix or workaround

Martin
 
I have the samilor problem,but I resolved it;
1. Do not remove the row you want to remove directly,just store it in
an array;
Codes are like below:
private int[] delIndex = null;
pushDelIndex(row.CurrentRow.Index);
private void pushDelIndex(int _index){
if(delIndex==null){
delIndex=new int[]{_index};
}else{
Array.Resize(ref delIndex,delIndex.Length+1);
delIndex[delIndex.Length - 1] = _index;
}
}

2. Then open a thread when the program start;
Codes are like below:
Thread delTh = new Thread(new ThreadStart(delRowThread));
delTh.Start();

3. Use the thread to check the array delIndex every 100 millseconds£¬if
it is not null,the call the function delRow;
Codes are like below:
void delRowThread() {
while (delFlag) {
if (delIndex != null) {
if (deling == false)
{
delRow();
}
}
Thread.Sleep(100);
}
}

private delegate void delRowCallBack();
void delRow() {
if (PlayList.InvokeRequired)
{
deling = true;
delRowCallBack o = new delRowCallBack(delRow);
this.Invoke(o);
}
else {
for (int i = 0; i < delIndex.Length; i++) {
PlayList.Rows.RemoveAt(delIndex);
}
deling = false;
delIndex = null;
}
}
 
Back
Top