Threading...

V

VJ

The below 2 func is in my Main Form..

public static void Main() {

object Arr;

ThreadPool.QueueUserWorkItem(new WaitCallback(GetLatestRptData),Arr);


}


private void GetLatestRptData(object Arr1)
{

'Check update Report XML file (data1.xml).. in a location


}


After the main Form loads I display a summary page. Then the user has a
button on the summary which they can click to go to the detail page. When
the Detail Page loads it will read data1.xml. If the thread has not
completed on the main Form load & is still updating the data1.xml, I would
want to wait for the Detail page to wait & then read the data1.xml. How do I
accomplish this? Can somebody give me a skeleton of Functions that indicates
the communcication. I know i need to use AutoResetEvent, but sure of how to
place the functions


Thanks
 
D

Dave

You can use a delegates "implied" BeginInvoke method, which will run an asyncronous process on a thread-pooled thread:

private delegate void RtpDataInvoker(object Arr1);

public static void Main()
{
RtpDataInvoker invoker = new GetLatestRtpData(dsa);
IAsyncResult result = invoker.BeginInvoke(Arr, null, null);

try
{
// Todo: async process here

// If you need to call a method that has to wait for the process to complete, just pass "result" to the method and
// use the following code:

if (!result.IsCompleted && !result.AsyncWaitHandle.WaitOne(10000, false))
// If the async process is not completed, wait 10 seconds
{
// Todo: timeout expired
}
}
finally
{
invoker.EndInvoke(result);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top