Vb.net异步功能

编程入门 行业动态 更新时间:2024-10-28 16:28:43
本文介绍了Vb异步功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我有一个问题,目前没有找到任何解决方案: 我有一个属性 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(ManualResetEvent或AutoResetEvent)上等待.在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异步功能

本文发布于:2023-11-08 02:24:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568072.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   Vb   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!