3

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!

greggorob64
  • 2,487
  • 2
  • 27
  • 55
  • +1 for a well-written question. -1 for using a C# tag and then writing C++CLI code. I get seasick looking at the shameful, ugly mess that is C++CLI. – Tergiver Jul 30 '10 at 20:32

1 Answers1

3

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
  • 554,122
  • 78
  • 1,158
  • 1,373
  • 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 Jul 30 '10 at 20:42