等待任务完成 [英] Waiting for a task to done

查看:139
本文介绍了等待任务完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好程序员,

在我的程序中我有一个计算出我的程序。我的意思是我的代码插入程序,将数据发送到另一个程序(由我编写)进行计算,然后它接收计算数据。 (我在这两个程序之间的联系就像管道 C#异步命名管道 [ ^ ])



发送计算数据后我需要延迟进行下一行代码,直到计算出的数据回来。

我的代码:



 ... 
_pipeClient = new PipeClient();
_pipeClient.Send(Cloud_Intelligent_Output, TestPipe 1000 );
_ctr ++;
(某些代码 for 等待结果返回)

...(其他一些代码,我想停止运行,直到结果< span class =code-keyword>返回
返回)





请不要定时和借口我太可怕了。 :)

解决方案

您是否尝试过选择异步并等待C#5.0和.Net 4.5的功能?

这是link有如何做的例子



C#5.0中的异步编程使用async并等待





欲了解更多详情你可以参考书

•C#5.0简而言之:Joseph Albahari(作者),Ben Albahari(作者)



告诉我如果这对你有帮助....


如果你不想使用.NET 4.5(因此,Visual Studio 2012),你可以使用AutoResetEvent [ ^ ]功能。



这是一个更具体的例子你需要。 [ ^ ]

hi programmers,
in my program i have a compute out of my program. i mean my program in meddle of codes, send a data to another program (which written by me) for computing and then it receive the computed data. (my connection between this two program is like Pipe C# Async Named Pipes[^])

after sending data for compute i need a delay for doing next line of codes until computed data come back.
my codes:

...
      _pipeClient = new PipeClient();
      _pipeClient.Send(Cloud_Intelligent_Output, "TestPipe", 1000);
      _ctr++;
      ( some code for waiting until result back )

... (Some other codes which i want stop running until result return back)



Please don't Timer and excuse from my awful Asking. :)

解决方案

Have you tried option of async and await feature of C# 5.0 and .Net 4.5?
This is link has example of how to do it

Asynchronous Programming in C# 5.0 using async and await


For more details you can refer to book
•C# 5.0 in a nutshell: Joseph Albahari (Author), Ben Albahari (Author)

Let me know if this helps you....


If you don't want to use .NET 4.5 (and therefore, Visual Studio 2012), you can use the AutoResetEvent [^]feature.

Here is an example more specific to what you need.[^]


这篇关于等待任务完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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