问题描述
class CommandLine2
{
static void Main(string[] args)
{
System.Console.WriteLine("Number of command line parameters = {0}", args.Length);
foreach (string s in args)
{
System.Console.WriteLine(s);
}
}
}
这是控制台应用程序,将从WCF火任务的例子。
This is an example of the console app that will fire the task from a WCF.
我得到了按行触发一组上的CSV文件线检查的一个项目,我创建一个控制台应用程序,将做任务。我需要的是运行这个异步所以它会打每行和每几秒钟左右后说结束任务。我希望它是有效的,这就是为什么。我将使用WCF,所以如果你知道一种方法来运行命令异步请指导我。
I got a project that fires a set of check on csv files line by line and I am creating a console app that will do the task. What I need is to run this async so it will hit each row and after say around few seconds end the task. I want it to be efficient that's why. I will be using a WCF so if you know a way to run the command async please guide me.
推荐答案
如果你使用WCF,你应该能够使客户端服务器基准包括基于任务的异步客户端调用。
If you're using WCF, you should be able to make the client server reference include Task-based asynchronous client calls.
您会那么只需要异步调用操作(S)。
You'd then just need to call the operation(s) asynchronously.
假设你在一个控制台应用程序的工作,但是,您可能不希望使用异步
/ 等待
,而是直接关火操作,并使用 Task.WaitAll
或相似。在一个控制台应用程序与异步操作的问题是,没有电流的同步环境,所以你必须要小心不要让应用程序关闭,直到您的异步工作完成。
Given that you're working in a console application, however, you may not want to use async
/await
, and instead just fire off the operations, and use Task.WaitAll
or similar. The problem with async operations in a console app is that there is no current synchronization context, so you need to be careful not to let the application shut down until your async work is completed.
这篇关于运行控制台异步导致更有效的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!