Situation: I have a console application that is touching a 3rd party software (Sage). The issue I am running into is when calling the method getCompanyAvailability(), the application times out (currently working with the creator of the API to figure out why). In the meantime, I am attempting to terminate the execution if I am waiting for a response for more than a set period of time. The method getCompanyAvailability just returns an integer. It seems to hit "WriteLog("Temp Message Test")" and then just sits there.... This was the code I put in place:
//hung up here
var getSageCompanyAvailability = Task.Run(() =>
{
return sageConnector.GetCompanyAvailability(companyName, "APIUser", "N3wPas$w0rd");
});
bool isCompletedSuccessfully = getSageCompanyAvailability.Wait(TimeSpan.FromMilliseconds(15000));
WriteLog("Temp Message Test");
if (isCompletedSuccessfully)
{
companyAvailabilityResponse = getSageCompanyAvailability.Result;
WriteLog("Company Availability: " + companyAvailabilityResponse);
}
else
{
sageConnector.DisableRequests();
sageConnector.DeIntializeAPI();
//If Succesful, still exit app.
Environment.Exit(0);
throw new TimeoutException("Getting Company Availability Timed Out. Ending Task...");
}
Am I missing any async issues with isCompletedSuccessfully getting properly set or am I using .Wait incorrectly here?