I am trying to send 100 messages to an web api from a console application. But the program is ending before sending the messages to the web api. If I put Console.ReadLine();
at the end it is working. Can any one help me with this issue?
I've posted the code I used below.
static void Main(string[] args)
{
CreateLog();
}
private static void CreateLog()
{
for(int i=0;i<100;i++)
ProcessLog(new LogMessage() { });
}
private static void ProcessLog(LogMessage message)
{
//Post message to web service
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(@"web api url");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
HttpContent contentPost = new StringContent(
JsonConvert.SerializeObject(message),
Encoding.UTF8,
"application/json");
client.PostAsync("api/xxx", contentPost);
}