Skip to content

Commit 8306d87

Browse files
committed
Simplify thread safety now that we have a wait in place
1 parent 3df26d2 commit 8306d87

File tree

1 file changed

+24
-33
lines changed

1 file changed

+24
-33
lines changed

dotnet/src/webdriver/DriverService.cs

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -240,46 +240,37 @@ public async Task StartAsync()
240240
{
241241
if (this.driverServiceProcess == null)
242242
{
243-
lock (this.driverServiceProcessLock)
244-
{
243+
this.driverServiceProcess = new Process();
245244

246-
if (this.driverServiceProcess == null)
245+
try
246+
{
247+
if (this.DriverServicePath != null)
247248
{
248-
var driverServiceProcess = new Process();
249-
250-
try
249+
if (this.DriverServiceExecutableName is null)
251250
{
252-
if (this.DriverServicePath != null)
253-
{
254-
if (this.DriverServiceExecutableName is null)
255-
{
256-
throw new InvalidOperationException("If the driver service path is specified, the driver service executable name must be as well");
257-
}
258-
259-
driverServiceProcess.StartInfo.FileName = Path.Combine(this.DriverServicePath, this.DriverServiceExecutableName);
260-
}
261-
else
262-
{
263-
driverServiceProcess.StartInfo.FileName = new DriverFinder(this.GetDefaultDriverOptions()).GetDriverPath();
264-
}
251+
throw new InvalidOperationException("If the driver service path is specified, the driver service executable name must be as well");
252+
}
265253

266-
driverServiceProcess.StartInfo.Arguments = this.CommandLineArguments;
267-
driverServiceProcess.StartInfo.UseShellExecute = false;
268-
driverServiceProcess.StartInfo.CreateNoWindow = this.HideCommandPromptWindow;
254+
this.driverServiceProcess.StartInfo.FileName = Path.Combine(this.DriverServicePath, this.DriverServiceExecutableName);
255+
}
256+
else
257+
{
258+
this.driverServiceProcess.StartInfo.FileName = new DriverFinder(this.GetDefaultDriverOptions()).GetDriverPath();
259+
}
269260

270-
DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs(driverServiceProcess.StartInfo);
271-
this.OnDriverProcessStarting(eventArgs);
261+
this.driverServiceProcess.StartInfo.Arguments = this.CommandLineArguments;
262+
this.driverServiceProcess.StartInfo.UseShellExecute = false;
263+
this.driverServiceProcess.StartInfo.CreateNoWindow = this.HideCommandPromptWindow;
272264

273-
driverServiceProcess.Start();
274-
}
275-
catch
276-
{
277-
driverServiceProcess.Dispose();
278-
throw;
279-
}
265+
DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs(this.driverServiceProcess.StartInfo);
266+
this.OnDriverProcessStarting(eventArgs);
280267

281-
this.driverServiceProcess = driverServiceProcess;
282-
}
268+
this.driverServiceProcess.Start();
269+
}
270+
catch
271+
{
272+
this.driverServiceProcess.Dispose();
273+
throw;
283274
}
284275
}
285276

0 commit comments

Comments
 (0)