简体   繁体   中英

C# return an a class

I'm using FluorineFx to send/receive AMF3 data over server.

 netConnection.Call("my-amf", "zend", "Ka_Services_Park", "getCompleteParkOfUser", new GetCustomersHandler(), new object[] { "msg_2580671638", "20251876" });

    public class GetCustomersHandler : IPendingServiceCallback
    {
        public void ResultReceived(IPendingServiceCall call)
        {
            object result = call.Result;
        }
    }

i want to return response from class GetCustomersHandler to class from was called i called GetCustomersHandler in netConnection.Call in Form1 class, i want to return/get response (object result) from GetCustomersHandler to Form1.

Have your callback object store the result as a property.

public class GetCustomersHandler : IPendingServiceCallback
{
    GetCustomersHandler()
    {
        this.Signal = new ManualResetEvent(false);
    }

    public void ResultReceived(IPendingServiceCall call)
    {
        this.Result = call.Result;
        this.Signal.Set();
    }

    public ManualResetEvent Signal { get; protected set; }
    public object Result { get; protected set; }
}

In the calling function, hold on to your callback object. Then when netConnection.Call() returns, you can retrieve the value

GetCustomersHandler callback = new GetCustomersHandler();
netConnection.Call("my-amf", "zend", "Ka_Services_Park", "getCompleteParkOfUser", callback, new object[] { "msg_2580671638", "20251876" });
callback.WaitOne();
object result = callback.Result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM