What should you do?

A class library named MathLib contains the following code.

public class MathClass : MarshalByRefObject
{
public decimal DoHugeCalculation(int iterations)
{
decimal result;
//Some very lengthy calculations …
return result;
}
}

The MathLib class is hosted in a .NET Framework remoting server application.
A Windows application project running on a client computer contains the following class.

public class MathClient
{
public void ProcessHugeCalculation(int iterations)
{
MathClass cm = new MathClass();
decimal decRes = cm.DoHugeCalculation(iterations);
//process the result …
}
}

The MathClient class must call the MathClass class asynchronously by using remoting.
A callback must be implemented to meet this requirement.
You need to complete the implementation of the MathClient class.

What should you do?

A class library named MathLib contains the following code.

public class MathClass : MarshalByRefObject
{
public decimal DoHugeCalculation(int iterations)
{
decimal result;
//Some very lengthy calculations …
return result;
}
}

The MathLib class is hosted in a .NET Framework remoting server application.
A Windows application project running on a client computer contains the following class.

public class MathClient
{
public void ProcessHugeCalculation(int iterations)
{
MathClass cm = new MathClass();
decimal decRes = cm.DoHugeCalculation(iterations);
//process the result …
}
}

The MathClient class must call the MathClass class asynchronously by using remoting.
A callback must be implemented to meet this requirement.
You need to complete the implementation of the MathClient class.

What should you do?

A.
Modify the MathClient class as follows:
public class MathClient
{
public delegate void DoHugeCalculationDelegate(decimal result);
public event DoHugeCalculationDelegate DoHugeCalculationResult;
public void DoHugeCalculationHandler(decimal result)
{
DoHugeCalculationResult(result);
}
public void ProcessHugeCalculation(int iterations)
{
//Hook up event
handler here… …
}
}

B.
Apply the Serializable attribute to the MathClient class.

C.
Modify the MathClient class as follows:
public class MathClient
{
private delegate decimal DoHugeCalculationDelegate(int iterations);
private void DoHugeCalculationCallBack(IAsyncResult res)
{
AsyncResult aRes = (AsyncResult)res;
decimal decRes = ((DoHugeCalculationDelegate)aRes. AsyncDelegate).EndInvoke(res);
//process the result …
}
public void ProcessHugeCalculation(int iterations)
{
MathClass cm = new MathClass();
DoHugeCalculationDelegate del = new DoHugeCalculationDelegate(cm.DoHugeCalculation);
del.BeginInvoke(iterations, new AsyncCallback( DoHugeCalculationCallBack), null);
}
}

D.
Apply the OneWay attribute to all methods in the MathClass class.



Leave a Reply 0

Your email address will not be published. Required fields are marked *