troubleshooting Question

System.Diagnostics.Process being queued

Avatar of concept99
concept99 asked on
Visual Basic.NET
2 Comments1 Solution245 ViewsLast Modified:
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
'======================================================
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros