@@ -41,6 +41,7 @@ public abstract class DriverService : ICommandServer
4141 private bool hideCommandPromptWindow ;
4242 private bool isDisposed ;
4343 private Process driverServiceProcess ;
44+ private object driverServiceProcessLock = new object ( ) ;
4445 private TimeSpan initializationTimeout = TimeSpan . FromSeconds ( 20 ) ;
4546
4647 /// <summary>
@@ -258,38 +259,42 @@ public void Dispose()
258259 /// </summary>
259260 public void Start ( )
260261 {
261- if ( this . driverServiceProcess != null )
262+ if ( this . driverServiceProcess is null )
262263 {
263- return ;
264- }
265-
266- this . driverServiceProcess = new Process ( ) ;
264+ lock ( this . driverServiceProcessLock )
265+ {
266+ if ( driverServiceProcess is null )
267+ {
268+ this . driverServiceProcess = new Process ( ) ;
267269
268- if ( this . driverServicePath != null )
269- {
270- this . driverServiceProcess . StartInfo . FileName = Path . Combine ( this . driverServicePath , this . driverServiceExecutableName ) ;
271- }
272- else
273- {
274- this . driverServiceProcess . StartInfo . FileName = new DriverFinder ( this . GetDefaultDriverOptions ( ) ) . GetDriverPath ( ) ;
275- }
270+ if ( this . driverServicePath != null )
271+ {
272+ this . driverServiceProcess . StartInfo . FileName = Path . Combine ( this . driverServicePath , this . driverServiceExecutableName ) ;
273+ }
274+ else
275+ {
276+ this . driverServiceProcess . StartInfo . FileName = new DriverFinder ( this . GetDefaultDriverOptions ( ) ) . GetDriverPath ( ) ;
277+ }
276278
277- this . driverServiceProcess . StartInfo . Arguments = this . CommandLineArguments ;
278- this . driverServiceProcess . StartInfo . UseShellExecute = false ;
279- this . driverServiceProcess . StartInfo . CreateNoWindow = this . hideCommandPromptWindow ;
279+ this . driverServiceProcess . StartInfo . Arguments = this . CommandLineArguments ;
280+ this . driverServiceProcess . StartInfo . UseShellExecute = false ;
281+ this . driverServiceProcess . StartInfo . CreateNoWindow = this . hideCommandPromptWindow ;
280282
281- DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs ( this . driverServiceProcess . StartInfo ) ;
282- this . OnDriverProcessStarting ( eventArgs ) ;
283+ DriverProcessStartingEventArgs eventArgs = new DriverProcessStartingEventArgs ( this . driverServiceProcess . StartInfo ) ;
284+ this . OnDriverProcessStarting ( eventArgs ) ;
283285
284- this . driverServiceProcess . Start ( ) ;
285- bool serviceAvailable = this . WaitForServiceInitialization ( ) ;
286- DriverProcessStartedEventArgs processStartedEventArgs = new DriverProcessStartedEventArgs ( this . driverServiceProcess ) ;
287- this . OnDriverProcessStarted ( processStartedEventArgs ) ;
286+ this . driverServiceProcess . Start ( ) ;
287+ bool serviceAvailable = this . WaitForServiceInitialization ( ) ;
288+ DriverProcessStartedEventArgs processStartedEventArgs = new DriverProcessStartedEventArgs ( this . driverServiceProcess ) ;
289+ this . OnDriverProcessStarted ( processStartedEventArgs ) ;
288290
289- if ( ! serviceAvailable )
290- {
291- string msg = "Cannot start the driver service on " + this . ServiceUrl ;
292- throw new WebDriverException ( msg ) ;
291+ if ( ! serviceAvailable )
292+ {
293+ string msg = "Cannot start the driver service on " + this . ServiceUrl ;
294+ throw new WebDriverException ( msg ) ;
295+ }
296+ }
297+ }
293298 }
294299 }
295300
0 commit comments