Can AsyncCallback use a non-static delegate?

I am using .net remoting, with asynchronous function calls, to handle the ipc of my current project.

I had a problem when I would like a client:

  • Request information asynchronously
  • Continue loading GUI
  • When the ASynchronous call is complete, load it into gui

I am doing this with the following code

  GetFileTextDelegate ^svd       = gcnew GetFileTextDelegate(obj, &BaseRemoteObject::GetFileText);
  AsyncCallback       ^callback  = gcnew AsyncCallback(RecievedSomething);
  IAsyncResult        ^arValSet  = svd->BeginInvoke(callback, nullptr);

In the above example, RecievedSomething MUST be the static method in this example. Why is this? If I could make this function non-static, I could load my gui, and all is well.

My solution is to get Received. Something triggered the static event that my gui signs. This is cumbersome as it now requires 2 delegates and an event to handle my 1st asynchronous function call.

Is there a way to speed up AsyncCallback with a non-static function?

Thank!

+3
source share
1 answer

You can use a non-static method for your delegate AsyncCallback. You just need to specify it correctly. For example, to use this->ReceivedSomething:

AsyncCallback ^callback  = gcnew AsyncCallback(this, &MyClassType::RecievedSomething);
+3
source

Source: https://habr.com/ru/post/1757409/


All Articles