Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Asynchronous problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bernardpace@yahoo.com - 19 Aug 2005 11:13 GMT
Hi,

I am using the following code in C#,

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

...
// schema of tbShow is being loaded from an xsd file
tbRand = DrawEngine.GenerateAllDraws(tb­Rand, randSize, ref tbShow);
dataGridRandomized.DataSource = tbShow;
...

}

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­aTable table,

int tot, ref DataTable show);

private void menuItemStart_Click(object sender, System.EventArgs e)
{
 ...
 GeneratingAllDrawsDelegate dc = new
GeneratingAllDrawsDelegate(Dra­wEngine.GenerateAllDraws);
 AsyncCallback cb = new AsyncCallback(getResultAllDraw­s);
 IAsyncResult  ar = 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 = (GeneratingAllDrawsDelegate) ((AsyncResult)ar).AsyncDelegat­e;

 tbRand = del.EndInvoke(ref tbShow, ar);
 dataGridRandomized.DataSource = 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.
Thanks in Advance
n_o_s_p_a__m@mail.com - 19 Aug 2005 16:50 GMT
When you debug, is GenerateAllDraws ever called?
bernardpace@yahoo.com - 20 Aug 2005 08:30 GMT
Hi, Thanks for your help, but problem was solved in the following way:

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

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

del = (GeneratingAllDrawsDelegate) ((AsyncResult)ar).AsyncDelegat­e;
tbRand = del.EndInvoke(ref tbShow, ar);
dataGridRandomized.DataSource = tbShow;
}
}

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.