Can AsyncCallback use a non-static delegate?
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:
- ASynchronously request information
- Continue loading the GUI
- 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);
精彩评论