Link to home
Start Free TrialLog in
Avatar of concept99
concept99

asked on

System.Diagnostics.Process being queued

I have a service in VB.net that checks for a network connection every 15 seconds. If a connection is found, it automatically launches the installed VPN software. The problem that I am having is that when the system starts up, and the user logs in -- there is so much processing happening that the VPN software can't load before the service checks for it again 15 seconds later.

The results is that anywhere from 4-6 attempts are made to launch the process at the EXACT same time. I know it is the same time because I am logging when the call to start the software is made (logging to the EventLog). What I think is happening is that the system is so busy while starting up and logging in, that the requests to launch the software are getting queued, and then executed all at one.

Is there anyway to prevent this queueing and allow only 1 launch of the program?

Here is my code that is calling the VPN software:

'======================================================
Dim myProcess As New System.Diagnostics.Process()
Dim sVPN_Path As String

If System.Diagnostics.Process.GetProcessesByName("VPN").Length > 0 Then
      'vpn is already running
Else
      'vpn must not be started, so launch it...
      sVPN_Path = My.Computer.FileSystem.SpecialDirectories.ProgramFiles + "\vpn\"

      myProcess.StartInfo.FileName = sVPN_Path + "vpn.exe"
      myProcess.StartInfo.WorkingDirectory = sVPN_Path
      myProcess.StartInfo.UseShellExecute = False
      myProcess.StartInfo.CreateNoWindow = True
      myProcess.Start()
      
      System.Threading.Thread.Sleep(4000)
      
      If System.Diagnostics.Process.GetProcessesByName("ROVA").Length > 0 Then
            EventLog.WriteEntry("VPN_Service", "Starting VPN.", EventLogEntryType.Information)
      Else
            myProcess.Kill()
            EventLog.WriteEntry("VPN_Service", "Killing VPN.", EventLogEntryType.Warning)
      End If

      myProcess.Close()
      myProcess.Dispose()
      sVPN_Path = Nothing  
      Return
End If

myProcess.Close()
myProcess.Dispose()
sVPN_Path = Nothing
'======================================================
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of concept99
concept99

ASKER

That worked great!