Restart, but after a delay

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I need to restart my VB.NET 2.0 app but I need to delay the new
instance's start until I know the previous instance has ended and freed
up all use of its resources (DLLs). What I have is an app where the
EXE is basically a shell and there are multiple DLL "plug-in" modules.
Within the shell I have a "load new module" function which lets the
user import new plug-ins. When an updated plug-in is loaded, I can't
overwrite the DLL immediately since the DLL is in-use. What I am doing
is copying the new plug-in to a temporary location. Then when the app
starts, I check that location for new DLLs before I dynamically load
them. However, when I use Application.Restart or
System.Diagnostics.Process.Start(Application.ExecutablePath) to start
my new instance, followed immediate by an "End" statement, the new
instance is starting before the old instance completely ends.
Therefore, when the new instance trys to copy the new DLLs from the
temp location to the application folder, I get an exception. Does all
this make sense? Any ideas? TIA... Steve
 
Steve said:
I need to restart my VB.NET 2.0 app but I need to delay the new
instance's start until I know the previous instance has ended and freed
up all use of its resources (DLLs). What I have is an app where the
EXE is basically a shell and there are multiple DLL "plug-in" modules.
Within the shell I have a "load new module" function which lets the
user import new plug-ins. When an updated plug-in is loaded, I can't
overwrite the DLL immediately since the DLL is in-use. What I am doing
is copying the new plug-in to a temporary location. Then when the app
starts, I check that location for new DLLs before I dynamically load
them. However, when I use Application.Restart or
System.Diagnostics.Process.Start(Application.ExecutablePath) to start
my new instance, followed immediate by an "End" statement, the new
instance is starting before the old instance completely ends.
Therefore, when the new instance trys to copy the new DLLs from the
temp location to the application folder, I get an exception. Does all
this make sense? Any ideas? TIA... Steve

You could try something like this:

Imports System.Diagnostics

Private Sub LoadDlls()
Dim procs As Process()
Dim proc As Process
Dim currProcName As String

'Grab the current process name
currProcName = Process.GetCurrentProcess.ProcessName

'Look for all instances of that
' process and wait in a loop until
' there is only one instance of our
' process running
Do
procs = Process.GetProcessesByName(currProcName)
Loop While procs.Length > 1

' *** Load your DLL's here ***

End Sub

Basically, this code just waits until there is only one running
instance of the program in memory. At that point, you know that one
running instance has to be the one the code is running in right now, so
it's safe to modify the Dll's because any other instances of the
program have terminated completely.

Mike S
 
Back
Top