Hi,

I am using the following code in C#,

private void menuItemStart_Click(object sender, System.EventArgs e)
{
DataTable tbRand, tbShow;
int randSize;

.=2E.
// schema of tbShow is being loaded from an xsd file
tbRand =3D DrawEngine.GenerateAllDraws(tb=ADRand, randSize, ref tbShow);
dataGridRandomized.DataSource =3D tbShow;
.=2E.

}

This code works ok, and data is being showed correctly in datagrid.
Now I am trying to convert it to asynchronous code as shown below.

public delegate DataTable GeneratingAllDrawsDelegate(Dat=ADaTable table,

int tot, ref DataTable show);

private void menuItemStart_Click(object sender, System.EventArgs e)
{
...
GeneratingAllDrawsDelegate dc =3D new
GeneratingAllDrawsDelegate(Dra=ADwEngine.GenerateAllDraws);
AsyncCallback cb =3D new AsyncCallback(getResultAllDraw=ADs);
IAsyncResult ar =3D dc.BeginInvoke(tbRand, randSize, ref tbShow, cb,
null);
...
}

private void getResultAllDraws(IAsyncResult ar)
{
DataTable tbRand, tbShow;
GeneratingAllDrawsDelegate del;

// schema of tbShow is being loaded from an xsd file


del =3D (GeneratingAllDrawsDelegate) ((AsyncResult)ar).AsyncDelegat=ADe;

tbRand =3D del.EndInvoke(ref tbShow, ar);
dataGridRandomized.DataSource =3D tbShow;
}

When I execute this code, no data is being shown in datagrid(when
passing tbRand as DataSource same behaviour was given). I also tried
to place the tbShow into a DataSet and write the data to an XML file,
but no file is being created. Also no exception is being rised.

Can someone help me figure my problem out.=20
Thanks in Advance

Re: Asynchronous problem by n_o_s_p_a__m

n_o_s_p_a__m
Fri Aug 19 10:50:44 CDT 2005

When you debug, is GenerateAllDraws ever called?


Re: Asynchronous problem by bernardpace

bernardpace
Sat Aug 20 02:30:32 CDT 2005

Hi, Thanks for your help, but problem was solved in the following way:

private void getResultAllDraws(IAsyncResult ar)
{
if( dataGridRandomized.InvokeRequi=ADred )
{
dataGridRandomized.BeginInvoke=AD(new
AsyncCallback(getResultAllDraw=ADs), new object[]{ar});
}
else
{
DataTable tbRand, tbShow;
GeneratingAllDrawsDelegate del;

// schema of tbShow is being loaded from an xsd file

del =3D (GeneratingAllDrawsDelegate) ((AsyncResult)ar).AsyncDelegat=ADe;
tbRand =3D del.EndInvoke(ref tbShow, ar);
dataGridRandomized.DataSource =3D tbShow;=20
}=20
}