mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-19 12:59:30 -07:00
Make the Ping method thread-safe (#1905)
So we do not risk blocking the main UI thread
This commit is contained in:
parent
dbc924cac9
commit
6f9e142fb0
1 changed files with 16 additions and 12 deletions
|
@ -20,6 +20,7 @@ using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace CalculatorUITestFramework
|
namespace CalculatorUITestFramework
|
||||||
{
|
{
|
||||||
|
@ -146,7 +147,8 @@ namespace CalculatorUITestFramework
|
||||||
{
|
{
|
||||||
Uri status;
|
Uri status;
|
||||||
Uri service = this.ServiceUrl;
|
Uri service = this.ServiceUrl;
|
||||||
HttpClient httpClient = new HttpClient();
|
using (HttpClient httpClient = new HttpClient())
|
||||||
|
{
|
||||||
httpClient.Timeout = this.InitializationTimeout;
|
httpClient.Timeout = this.InitializationTimeout;
|
||||||
|
|
||||||
if (service.IsLoopback)
|
if (service.IsLoopback)
|
||||||
|
@ -158,8 +160,10 @@ namespace CalculatorUITestFramework
|
||||||
status = new Uri(service + "/status");
|
status = new Uri(service + "/status");
|
||||||
}
|
}
|
||||||
|
|
||||||
var httpResponse = httpClient.GetAsync(status);
|
var httpResponse = Task.Run(() => httpClient.GetAsync(status)).ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
return httpResponse.Result.IsSuccessStatusCode;
|
|
||||||
|
return httpResponse.IsSuccessStatusCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue