2014-01-07 2 views
0

웹 서버에서 현재 버전의 .exe를 기반으로 파일을 다운로드하는 응용 프로그램을 만들었습니다. 모든 검사가 완료되었지만 모든 기능이 제대로 작동하지만 멈출 수있는 방법이 필요합니다. 파일 추출이 완료 될 때까지 기다리십시오. 느린 PC 및/또는 큰 파일의 경우에 대해 어떻게 가능합니까? 또한 추출이 완료된 후 파일을 삭제하려고합니다.C# 파일 압축 대기

추출은 winrar sfx 압축을 사용하여 수행 된 다음 응용 프로그램에서 파일을 다운로드하고 나중에 시작합니다.

미리 감사드립니다. 코드는 다음과 같습니다. 처음으로 네트워킹으로 작업하는 것은 처음이며, 여전히 자기 가르침을 가지고 있습니다. 그렇다면 의미있는 코멘트를 남겨 주시기 바랍니다.

private void Completed(object sender, AsyncCompletedEventArgs e) 
{ 
    Process.Start("update.exe"); 
} 

private void downloadfile(string filenumber) 
{ 
    MessageBox.Show("Download working"); 

    WebClient webClient = new WebClient(); 
    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); 
    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); 

    webClient.DownloadFileAsync(new Uri("http://127.0.0.1/Update/update"+filenumber+".exe"), @"update.exe"); 

    label1.Text = "Downloading Update" + filenumber + "..."; 
    string filepath = "http://127.0.0.1/Update/update"+filenumber+".exe"; 

    webClient.OpenRead(filepath); 

    Int64 bytes_total = Convert.ToInt64(webClient.ResponseHeaders["Content-Length"]); 
    string updatelength = Convert.ToString((bytes_total/1024).ToString()); 
    label2.Text = updatelength + "KB"; 
} 
+11

당신은 어떻게 추출을 수행합니까? – CodeCaster

+0

병렬 작업 라이브러리 http://msdn.microsoft.com/en-us/library/dd537609(v=vs.110).aspx를 확인하십시오. 어쩌면 Task.WaitAll – reggaeguitar

+0

을 사용합니다. 나는 winrar를 사용하여 파일을 압축하고 백그라운드에서 자동 실행되도록 만들고 C#을 통해 파일을 자동으로 시작합니다. –

답변

1

SFX 파일 :

Process proc = Process.Start("update.exe", "-s"); // extract in the silent mode 
proc.WaitForExit(); 
File.Delete("update.exe"); 
+0

고마워, 잘 했어! 더 많은 여유 시간이있을 때마다 도서관에서 계속 살펴볼 것입니다. 모두에게 감사드립니다. –

0

방법 1 다음 SFXs EXE - 스레드가 여전히 실행중인 경우 그냥 확인. 사용 된 RAR 싶게가 SFX 압축을 풀고 파일이 계속 액세스 (차단) 여부를 확인 주기적 : 빠른 해결책은

process.WaitForExit(); 

방법 두 것이다.

하지만 난 엄격하게 rar 라이브러리를 사용하는 것이 좋습니다. 그것은 "진짜 인 경우 http://nunrar.codeplex.com/

도서관 신경 안 : 그래서 당신은 (심지어 OS에 따라 다를 수 있습니다) RAR의 특정 설치

다음 라이브러리가 필요에 맞게 보인다에 의존하지 않는 "RAR 또는 당신은 다음과 같은 작업을 수행 할 수