WaitForExit: No process is associated with this object.

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

Using the following code, I get the error "No process is associated with
this object" when calling the WinZip.WaitForExit() method. After I
click the "Break" or "Continue" button on the dialog, the app exits but
then the command window opens and the process runs on its own. Could
the "WaitForExit" call be happening too soon?

Private Sub ZipDirs(ByVal PCName As String)
Dim WinZip As New System.Diagnostics.Process
Dim args As String = " -Pru -ex " & lblFolder.Text & "\" & PCName &
".zip @""" & appPth & "WksBkup.txt"""
Dim SI As New ProcessStartInfo("c:\Program Files\WinZip\wzzip.exe",
args)
'WinZip.EnableRaisingEvents = True
WinZip.Start(SI)
WinZip.WaitForExit()
End Sub
 
I finally got it to work, see the code below. I don't understand why
some ways work and others dont.


Private Sub ZipDirs(ByVal PCName As String)
Dim WinZip As New System.Diagnostics.Process
Dim args As String = " -Pru -ex " & lblFolder.Text & "\" & PCName &
".zip @""" & appPth & "WksBkup.txt"""
Dim SI As New ProcessStartInfo("c:\Program Files\WinZip\wzzip.exe",
args)

'THIS WORKS (WaitForExit waits)
WinZip.StartInfo = SI
WinZip.Start()

'THIS DOESN'T WORK (WaitForExit throws)
WinZip.Start(SI)

WinZip.WaitForExit()
End Sub
 
Hello Terry,

Your mistake is that "Start(ByVal ProcessStartInfo) as Process" is Shared
method of Process class and is returning a new Process object.

For now you are:
1. Creating new process without any startup info (Dim WinZip as New ...);
2. Starting a NEW process with SI startupinfo object (WinZip.Start(SI));
created process object goes into nothing;
3. Calling WaitForExit method of WinZip object which is actually empty
(WinZip.WaitForExit()), obviously causing an exception.

So, you need to remake your code:

~
Dim args as String = "...", SI As New ProcessStartInfo(...)
Dim WinZip As Process = Process.Start(SI) REM (!)
WinZip.Start()
WinZip.WaitForExit()
~

Or:

~
Dim args, SI...
Dim WinZip As New Process()
WinZip.StartInfo = SI
WinZip.Start()
WinZip.WaitForExit()
~

I hope this helps.

Dragon
 
Back
Top