2009-11-09 4 views
0

프로세스가 끝날 때 문제가 있습니다.프로세스 끝 문제

은 내가 zip 파일에 필요 - 그리고 난 압축 후 - 메시지 박스가 표시하지만 내가 ...이 zip 파일로

문제가 몇 가지 일을 할 필요가 - 내가 프로세스가 종료되지 않은 것으로 나타났습니다.

어떻게 프로세스가 끝났는지 확실히 알 수 있습니까?

내 지퍼 샘플 : 내가 VS2008 C#을의 WinForm에서 작업

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"); 

내가 우편으로

파일을 뭔가를해야만 할 때 때문에 프로세스가 여전히 작동하는지 알고, 내가 파일이 사용 중임을 알리는 오류가 발생합니다. 그리고 1-2 분 동안 기다리면 나는 무엇을 할 수있다

이 zip 파일로 원한다.

+0

다른 전경 스레드가 활성화되어 있지 않으면 메시지 상자를 닫 자마자 프로세스가 종료되어야합니다. 왜 그것이 끝나지 않는다고 생각합니까? – Groo

답변

1

이 Windows App 또는 Console App입니까? 첫 번째 경우에는 Application.Exit()을 사용하십시오. 두 번째 한 게시물 전체 코드

1

quesion은 약간 분명하지 않지만 프로세스별로 System.Threading.Process를 의미하는 경우 Process.Exited 이벤트로 작업 할 수 있습니다. 프로세스가 완료되면 발생합니다.