views:

44

answers:

1

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 make 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!

+2  A: 

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);
Reed Copsey
I'll give this a try first thing monday morning, thanks! I didn't put two and two together and realize that AsyncCallback's is just a delegate, and its constructor should operate like one.
greggorob64