Vb.net异步功能 [英] Vb.net asynchrous function

查看:121
本文介绍了Vb.net异步功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个问题,目前没有找到任何解决方案:

我有一个属性 getX(),它调用一个函数 askX().

我的 askX()函数调用是服务器上的一个请求,该请求返回一个事件.

x值在 communication_X_RCVD()
中接收
所以我的问题:doh:,我该如何返回从 getX()属性的 communication_X_RCVD()中收到的值.

谢谢

ps:对不起,我的英文不好:sigh:

Hi all,
I have a problem and didn''t find any solution at the moment :

I have a property getX() who call''s a function askX().

My askX() function call''s a request on the server which returns an event.

The x value is received in a communication_X_RCVD()

So my question :doh: , how can I do to return the value received in my communication_X_RCVD() from my getX() property.

Thank''s

ps: sorry for my poor English :sigh:

推荐答案

大概是askX方法是异步的,因为它可能要花一些时间执行,而作者却没有这样做.希望您在等待时阻止它.阻止UI线程是不好的设计,因为它阻止您的应用程序与用户进行交互.

因此,第一个问题是:在服务器上执行请求时,您真的要getX阻止吗?

尼克
Presumably, the askX method is asynchronous because it may take some time to execute and the author didn''t want you to block while waiting for it. Blocking the UI thread is bad design because it stops your application from interacting with the user.

So, the first question is: do you really want getX to block while the request is executing on the server?

Nick


尼克,
如果我的应用程序被锁定,在这种情况下这不是问题.
所以是的,我想等待响应.

谢谢's

Pablo
Hi Nick,
It''s not a problem in this case if my application it''s locked.
So yes, I want to wait for the response.

Thank''s

Pablo


如果阻止正常,则需要进行一些同步.

您尚未发布足够的详细信息给我,无法给您提供代码,但这是一个开始:

getX()中,通过调用askX()启动异步操作.然后在EventWaitHandle(ManualResetEventAutoResetEvent)上等待.在communication_X_RCVD()中,将结果存储在可见字段中,然后用信号通知EventWaitHandle.当getX()恢复时,结果将可用.

如果您发布askX()communication_X_RCVD()的签名,我会更具体.

尼克
If blocking is ok, you will need some synchronization.

You haven''t posted enough details for me to give you code, but here is a start:

In getX(), start the asynchronous operation by calling askX(). Then wait on an EventWaitHandle ( ManualResetEvent or AutoResetEvent ). In communication_X_RCVD(), store the result in a visible field and then signal the EventWaitHandle. When getX() resumes, the result will be available.

If you post the signature of askX() and communication_X_RCVD(), I could be more specific.

Nick


这篇关于Vb.net异步功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆