Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space IceMaster and version 3.7.1

...

Anchor
ice_invoke
ice_invoke

Calling ice_invoke Asynchronously in C# with Tasks

The asynchronous mapping for ice_invoke resembles that of the static AMI mapping. The return values and the parameters operationmode, and inParams have the same semantics as for the synchronous version of ice_invoke.

The ice_invokeAsync method has the following signature:

Code Block
languagecsharp
titleC#
System.Threading.Tasks.Task<Ice.Object_Ice_invokeResult>
ice_invokeAsync(string operation,
                Ice.OperationMode mode,
                byte[] inParams,
                Ice.OptionalContext context = new Ice.OptionalContext(),
                System.IProgress<bool> progress = null,
                System.Threading.CancellationToken cancel = new System.Threading.CancellationToken());

The method sends (or queues) an invocation of the given operation and does not block the calling thread. It returns a Task that you can use in a number of ways, including blocking to obtain the result, configuring a continuation to be executed when the result becomes available, and polling to check the status of the request. Refer to the static AMI mapping for more information on the contextprogress and cancel arguments.

The ice_invokeAsync signature is consistent with the AMI mapping of operations that return multiple values, therefore it uses a structure as its result type:

Code Block
languagecsharp
titleC#
namespace Ice
{
    public struct Object_Ice_invokeResult
    {
        public Object_Ice_invokeResult(bool returnValue, byte[] outEncaps);
        public bool returnValue;
        public byte[] outEncaps;
    }
}

User exceptions are handled differently than for static asynchronous invocations. Calling ice_invokeAsync can raise Ice run-time exceptions but never raises user exceptions. Instead, the returnValue member of Object_Ice_invokeResult indicates whether the operation completed successfully (true) or raised a user exception (false). If returnValue is true, the byte sequence in outEncaps contains an encapsulation of the results; otherwise, the byte sequence in outEncaps contains an encapsulation of the user exception.

Ztop

Calling ice_invoke Asynchronously in C# with AsyncResult

Info

The AsyncResult API is deprecated and provided only for backward compatibility. New applications should use the Task API.

The asynchronous mapping for ice_invoke resembles that of the static AMI mapping. Multiple overloadings are provided to support the use of callbacks and request contexts. The return value and the parameters operation, mode, and inParams have the same semantics as for the synchronous version of ice_invoke.

...

Code Block
languagecsharp
titleC#
Ice.AsyncResult<Ice.Callback_Object_ice_invoke>
begin_ice_invoke(
    string operation,
    Ice.OperationMode mode,
    byte[] inParams);

Ice.AsyncResult<Callback_Object_ice_invoke>
begin_ice_invoke(
    string operation,
    Ice.OperationMode mode,
    byte[] inParams,
    Dictionary<string, string> context__);

bool end_ice_invoke(out byte[] outParams, AsyncResult r__);

User exceptions are handled differently than for static asynchronous invocations. Calling end_ice_invoke can raise Ice run-time exceptions but never raises user exceptions. Instead, the boolean return value of end_ice_invoke indicates whether the operation completed successfully (true) or raised a user exception (false). If the return value is true, the byte sequence contains an encapsulation of the results; otherwise, the byte sequence contains an encapsulation of the user exception.

...

Code Block
languagecsharp
titleC#
Ice.AsyncResult begin_ice_invoke(
    string operation,
    Ice.OperationMode mode,
    byte[] inParams,
    Ice.AsyncCallback cb__,
    object cookie__);

Ice.AsyncResult begin_ice_invoke(
    string operation,
    Ice.OperationMode mode,
    byte[] inParams,
    Dictionary<string, string> context__,
    Ice.AsyncCallback cb__,
    object cookie__);

Refer to the static AMI mapping for a callback example.

...