AsyncCallback 可以使用非静态委托吗?
我正在使用 .net 远程处理,通过异步函数调用来处理当前项目的 ipc。
我遇到了一个问题,我希望客户端:
- 异步请求信息
- 继续加载 GUI
- 当异步调用完成时,将其加载到 GUI
我使用以下代码执行此操作
GetFileTextDelegate ^svd = gcnew GetFileTextDelegate(obj, &BaseRemoteObject::GetFileText);
AsyncCallback ^callback = gcnew AsyncCallback(RecievedSomething);
IAsyncResult ^arValSet = svd->BeginInvoke(callback, nullptr);
在上面的示例中, 在此示例中,RecievedSomething 必须是静态方法。这是为什么?如果我可以使这个函数成为非静态的,我就可以加载我的 GUI,一切都很好。
我的解决方案是让 RecievedSomething 触发我的 gui 订阅的静态事件。这很麻烦,因为现在需要 2 个委托和一个事件来处理我的 1 个异步函数调用。
有没有办法让 AsyncCallback 与非静态函数一起工作?
谢谢!
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 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为
AsyncCallback
委托使用非静态方法。您只需正确指定它即可。例如,要使用this->ReceivedSomething
:You can use a non-static method for your
AsyncCallback
delegate. You just have to specify it correctly. For example, to usethis->ReceivedSomething
: