I am trying to get the response from a url, and when I use the await
and async
in my function, my Mutex
throws an error.
Error output :
System.ApplicationException
Object synchronization method was called from an unsynchronized block of code.
at System.Threading.Mutex.ReleaseMutex()
Code :
private async void getData ()
{
_mutex.WaitOne();
try
{
string url = "https://urllink.com";
HttpClient client = new HttpClient();
string response = await client.GetStringAsync(url);
}
catch (Exception e)
{
// TODO
throw e;
}
_mutex.ReleaseMutex();
}