i have problem with end of process
-
hi 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.
-
hi 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.
E_Gold wrote:
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
That may well be a wrong conclusion. The one way to know whether a process is (still) running or not, is by looking at the Task Manager's list. Here is what is probably going on: if you want write or delete access (anything other than read access) to a file that just got created (by yourself or someone else, does not matter), chances are you will find the file is being accessed by some other process, and your access is not granted. The other process very likely is some server code that is there to assist you somehow. Candidates are: - anti-virus software (Norton, McAfee, whatever) - indexing software (Google Desktop, MS Office, whatever) The common thing is these packages are looking all the time for new files, so they can inspect them. Microsoft is aware of the consequences; Windows Explorer will try rename and delete attempts up to five times (with one-second interval), and only reports failure if the action continues to fail for that time. The solution: 1. either use a different file name (not always acceptable) 2. or remove all background reader candidates (bad idea) 3. or implement the retry loop as Explorer has it (use a Windows.Forms.Timer for this) BTW: if all you need is Read, make sure to allow others to read as well, i.e. use File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read) Remark: in my experience, trying to open/append/close a file more often than once a second succeeds all the time, seems like the inspectors allow for at least one second of inactivity before opening the files themselves. :)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages