old amd callback object disappare in 3.7.2

ggslayerggslayer Member MingYi ZhangOrganization: renren.comProject: renren data platform
edited July 11 in Help Center

in 3.7.2, c# server side slice-generated code changed, from older "amd parameter" to the new task mode, I can't find the amd parameter from the parameter list in method.

in my usage expirence of amd, it is useful like this:

void (...amd  callback, int para1, int para2)
{
    // do something must sync
    // ex:  write to db

    // give client response first
    callback.ice_response();

    // do something async
    // ex: send a mq message or something longtime job
}

now, with the new async mode in c#, how this can be done?

Tagged:

Answers

  • xdmxdm ZeroC Staff La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    edited July 11
    public override Task<string> opStringAsync(Ice.Current current)
    {
        // do something must sync
        // ex:  write to db
        return Task<string>.Run(() =>
            {
                   // do something async
                    // ex: send a mq message or something longtime job
                    return "hello world!";
             });
    }
    

    Or simpler using async/await

    public override async Task<string> opStringAsync(Ice.Current current)
    {
         // do something must sync
         // ex:  write to db
    
         // await the async operation
         await xxxAsync();
         return "hello world!";
    }
    

    See AMD Tasks in C#

  • ggslayerggslayer Member MingYi ZhangOrganization: renren.comProject: renren data platform

    The answer not my question, the ice documents can describe my question:

    In doc3.6's "amd":
    An alternate use case for AMD is an operation that requires further processing after completing the client's request. In order to minimize the client's delay, the operation returns the results while still in the dispatch thread, and then continues using the dispatch thread for additional work.

    But in doc3.7 , this is disappear. how to implement the affect in 3.6's amd now?

  • xdmxdm ZeroC Staff La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    edited August 1

    With the new async API you cannot do exactly the same, that is why this was removed from the doc. You can do something similar for example:

    var t = Task.FromResult("hello world!");
    t.ContinueWith(previous =>
    {
        // do something async
        // ex: send a mq message or something longtime job
    });
    return t;
    
  • ggslayerggslayer Member MingYi ZhangOrganization: renren.comProject: renren data platform

    This resolve my question partly, like this:

    lock locker;

    locker.lock();      // this lock cross async proc, is invalid.
    var t = Task.FromResult("hello world!");
    t.ContinueWith(previous =>
    {
        //do long job1
        ....
    
        locker.unlock().
    
        //do long job2
        ...
    });
    return t;
    

    In this situation, all or part of async code could in the lock, but I can't use the lock in async

  • xdmxdm ZeroC Staff La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff

    Hi,

    C# doesn't allow the locks to be used with async code, you can implement something like this using SemaphoreSlim.WaitAsync

Sign In or Register to comment.