开发者

Can AsyncCallback use a non-static delegate?

开发者 https://www.devze.com 2023-01-10 03:01 出处:网络
I\'m using .net remoting, with asynchronous function calls to handle the ipc of my current project. I\'m running into an issue where I\'d like the client to:

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

I'm running into an issue where I'd like the client to:

  1. ASynchronously request information
  2. Continue loading the GUI
  3. When the ASynchronous call is complete, load it into the gui

I do 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 a static method in this example. Why is that? If I could m开发者_如何学Cake this function non-static, I could load my gui, and alls well.

My solution is to have RecievedSomething fire off a static event that my gui subscribes to. This is cumbersome in that it will now require 2 delegates and an event to have my 1 asynchronous function call handled.

Is there a way to hace AsyncCallback work with a non-static function?

Thanks!


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

AsyncCallback ^callback  = gcnew AsyncCallback(this, &MyClassType::RecievedSomething);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号