Anfang des Inhaltsbereichs

Vorgehensweisen Asynchronous Methods Dokument im Navigationsbaum lokalisieren

With SAP .NET Connector, we can take advantage of many features of the CLR including support for easy asynchronous programming. This powerful feature is not available on any other SAP connector at this time. In all other connectors, BAPI and RFC calls are synchronous calls.

When we use asynchronous methods from the SAP .NET Connector wizard, the proxy contains two additional methods Begin<RFC name> and End<RFC Name>.

When Begin<RFC name> is called, CLR queues the request and returns immediately to the caller. The target method will be on thread from the thread pool. The original thread is free to continue executing in parallel to the target method. If a callback has been specified on the Begin<RFC name>, it will be called when the target method returns. In the callback, the End<RFC name> method is used to obtain the return value and the in/outparameters. If the callback was not specified on the Begin<RFC name>, then End<RFC name> can be used on the original thread that submitted a request.

When working with asynchronous calls, we need three additional variables compared to a synchronous RFC call

When working with asynchronous calls, we need three additional variables compared to a synchronous RFC call.

 

Variable

What It Does

System.IAsyncResult asyncresult

A return of IAsyncResult is required to implement Asynchronous Method signatures. The result of the call (IAsyncResult) is returned from the begin operations, and can be used to obtain status on whether the asynchronous begin operations has completed. The result object is passed to the end operation, which returns the final return value of the call.

System.AsyncCallback callback

A delegate class that is called when the operation has completed. If null, no delegate is called. We can either use a callback delegate as shown below or pass the AsyncCallback delegate as null. In that case, no delegate will be called and we have to check the status ourselves. To check the status we can check the AsyncResult.IsCompleted property or if we are using a callback, this delegate will be called automatically when the method has completed.

object asyncState

Extra information supplied by the caller

 

Example

The following Winform sample shows the code for asynchronous method call (SAPAsyncSearch method).

 

private void SAPAsyncSearch()

/* this routine calls RFC_CUSTOMER_GET using .NET asynchronous

 * method invocation. When the function is completed asynchronously in SAP,

 * the function "myfunction" is called. */

SAPConnect();

myAsyncState = null;

myCallback = new System.AsyncCallback(myFunction);

asyncresult = null;

try

{

asyncresult = proxy.BeginRfc_Customer_Get(g_custNo, g_custName, ref brfcknA1Table1, myCallback, myAsyncState);

}

catch (Exception ex)

{

MessageBox.Show("Error returned in Async search\n" + ex.ToString(), "SAP Async Search problem");

return;

}

}

 

Ende des Inhaltsbereichs