J
Jeff
Hey
..NET 2.0
In my app I'm about to program some code which retrieve a XML file from
somwhere on the Internet. and then parses the XML - just looping through the
records in the XML document and collecting a value at each record....
This task will run each day to collect this data...
Because parsing this XML document can take a while, so I'll set a delegate
to do the processing in the thread pool....
PROBLEM
If no XML file exist then the delegate should throw an exception and stop
executing... my code start a delegate with BeginInvoke but how should I
catch this exception in the program..?? Should I just implement a try/catch
block in the ExecuteExample method and if no file XML file exists when
TestMethod executes then throw an exception, will then this exception be
caught in the process started the delegate thread? This confuses me a bit
Here is some example code describing my problem:
delegate decimal TestDelegate();
private decimal TestMethod()
{
//Do XML processing here
}
public decimal ExecuteExample()
{
IAsyncResult aResult = null
TestDelegate d = new TestDelegate(TestMethod)
aResult = d.BeginInvoke(null, null);
if (!aResult.IsCompleted)
aResult.AsyncWaitHandle.WaitOne();
decimal value = d.EndInvoke(aResult);
}
any suggestions?
..NET 2.0
In my app I'm about to program some code which retrieve a XML file from
somwhere on the Internet. and then parses the XML - just looping through the
records in the XML document and collecting a value at each record....
This task will run each day to collect this data...
Because parsing this XML document can take a while, so I'll set a delegate
to do the processing in the thread pool....
PROBLEM
If no XML file exist then the delegate should throw an exception and stop
executing... my code start a delegate with BeginInvoke but how should I
catch this exception in the program..?? Should I just implement a try/catch
block in the ExecuteExample method and if no file XML file exists when
TestMethod executes then throw an exception, will then this exception be
caught in the process started the delegate thread? This confuses me a bit
Here is some example code describing my problem:
delegate decimal TestDelegate();
private decimal TestMethod()
{
//Do XML processing here
}
public decimal ExecuteExample()
{
IAsyncResult aResult = null
TestDelegate d = new TestDelegate(TestMethod)
aResult = d.BeginInvoke(null, null);
if (!aResult.IsCompleted)
aResult.AsyncWaitHandle.WaitOne();
decimal value = d.EndInvoke(aResult);
}
any suggestions?