Update MakeHttpRequest to use TaskFactory for async tasks
MakeHttpRequest is an async method which is called in synchronous way
In order to avoid a deadlock (for example, when run using XUnit),
we create a new task to run the async method.
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using OpenQA.Selenium.Internal;
@@ -145,7 +146,15 @@ public virtual Response Execute(Command commandToExecute)
HttpResponseInfo responseInfo = null;
try
{
- responseInfo = this.MakeHttpRequest(requestInfo).GetAwaiter().GetResult();
+ // Use TaskFactory to avoid deadlock in multithreaded implementations.
+ responseInfo = new TaskFactory(CancellationToken.None,
+ TaskCreationOptions.None,
+ TaskContinuationOptions.None,
+ TaskScheduler.Default)
+ .StartNew(() => this.MakeHttpRequest(requestInfo))
+ .Unwrap()
+ .GetAwaiter()
+ .GetResult();
}
catch (HttpRequestException ex)
{
