An application calls a Web method asynchronously by using the following code.
(Line numbers are included for reference only.)
01 void ProcessData() {
02 ProcessingService serviceProxy = new ProcessingService();
03 IAsyncResult asyncResult = null;
04 asyncResult = serviceProxy.BeginProcess(data, null, null);
05 while (!asyncResult.IsCompleted) {
06 Thread.Sleep(1000);
07 }
08
09 serviceProxy.EndProcess(asyncResult);
10 }
You need to ensure that the application can process and log any exceptions raised by the Web method.
What should you do?
A.
Replace line 09 with the following code.
try
{
serviceProxy.EndProcess(asyncResult);
}
catch (Exception ex)
{
LogException(ex);
}
B.
Replace lines 05, 06, and 07 with the following code.
try
{
while (!asyncResult.IsCompleted)
{
Thread.Sleep(1000);
}
}
catch (Exception ex)
{
LogException (ex);
}
C.
Replace line 08 with the following code.
if (asyncResult.AsyncState is Exception)
LogException (asyncResult.AsyncState);
D.
Replace line 04 with the following code.
try
{
asyncResult = serviceProxy.BeginProcess(data, null,null);
}
catch (Exception ex)
{
LogException (ex);
}