Gold
Gold

Reputation: 62424

problem with end of process

i have problem with end of process.

i need to zip file - and after i zip - i need to do some thing with this zip file...

the problem is, although the messagebox appear - i noticed that the process is not end.

how i can know for sure that the process is end ?

my zip sample:

try
{
     if (File.Exists(@"c:\DaZIP\Bind.sdf"))
         File.Delete(@"c:\DaZIP\Bind.sdf");
     File.Copy(Application.StartupPath + @"\Bind.sdf", @"c:\DaZIP\Bind.sdf");

     byte[] sampleBuffer = null;
     ZipEntry sampleZipFile = null;
     FileStream sampleFileStream = null;

     ZipOutputStream sampleOutputStream = new 
         ZipOutputStream(File.Create(Application.StartupPath + @"\Bind.zip"));
     sampleOutputStream.Password = "12345";
     sampleOutputStream.SetLevel(9);

     foreach (string sampleFile in Directory.GetFiles(@"c:\DaZIP")) 
     {
         sampleZipFile = new ZipEntry(Path.GetFileName(sampleFile));
         sampleOutputStream.PutNextEntry(sampleZipFile);

         sampleFileStream = File.OpenRead(sampleFile);
         sampleBuffer = new byte[sampleFileStream.Length];
         sampleFileStream.Read(sampleBuffer, 0, sampleBuffer.Length);
         sampleOutputStream.Write(sampleBuffer, 0, sampleBuffer.Length);
     }

     sampleOutputStream.Finish();
     sampleOutputStream.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message ,"",0, MessageBoxIcon.Exclamation);
    return;
}

MessageBox.Show("End ZIP");

i work on VS2008 C# WinForm

i know that the process still work, because when i try to do somthing with the zip

file, i get error that the file is in use. and if i wait for 1-2 minute, i can do what i

want with this zip file.

Upvotes: 0

Views: 131

Answers (2)

Christian
Christian

Reputation: 4342

The quesion is a bit unclear, but if by Process you mean System.Threading.Process, you can work with the Process.Exited event. It's raised when the process finishes.

Upvotes: 1

PiotrK
PiotrK

Reputation: 4453

Is this Windows App or Console App? In the first case, use Application.Exit(). In the second one - post entire code

Upvotes: 1

Related Questions