Run console Asynchronously to result a more efficient output

给你一囗甜甜゛ 提交于 2019-12-11 16:00:36

问题


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);
    }
}
}

This is an example of the console app that will fire the task from a 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.


回答1:


If you're using WCF, you should be able to make the client server reference include Task-based asynchronous client calls.

You'd then just need to call the operation(s) asynchronously.

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.



来源:https://stackoverflow.com/questions/18388419/run-console-asynchronously-to-result-a-more-efficient-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!