Run console Asynchronously to result a more effici

2019-09-06 20:58发布

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条回答
欢心
2楼-- · 2019-09-06 21:41

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.

查看更多
登录 后发表回答