Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article has been moved to its new home here: https://benperk.github.io/msdn/2017/2017-03-how-i-called-an-asynchronous-method-from-a-loop.html
Check out some of my other articles I wrote in reagrds to ASP.NET Core and .Net Core
- How to call an async method from a console app main method
- How to deploy a .NET Core console application to Azure, WebJob
- .NET Core application, where is my EXE, how to publish
- Create a VNET and access an Azure VM hosted within it from an App Services Web App
- Create and deploy an ASP.NET Core Web API to Azure Windows
I wrote this article here where I showed "How to call an async method from a console app main method", but I needed also to call it numerous times. Here is the code snippet that illustrates how I did that.
public static void Main(string[] args)
{
try
{
int i = 0;
while (i < 10)
{
Task.Run(() => callWebApi()).Wait();
i++;
}
}
catch (Exception ex)
{
WriteLine($"[MAIN] There was an exception: {ex.ToString()}");
}
}
Simply, I used the Wait() method of the Task.
Comments
- Anonymous
March 08, 2017
The comment has been removed- Anonymous
March 28, 2017
@Kae, I appreciate very much your comments. I like the pattern you provide.
- Anonymous