2011-09-01 2 views
0

진행률 표시 줄을로드하는 동안로드하는 동안 취소 단추를 누르면 전체 응용 프로그램이 무엇을 하던지 중단합니다.진행률 표시 줄에서 취소 버튼을 누르면 프로그램을 멈추는 방법 C#

아래 코드는 진행률 표시 줄을 호출하는 코드입니다. 나는 누군가가 이것으로 도울 수 있을지 궁금해하고 있었다?

Loading loader = new Loading(); 


    private void lockButton_Click(object sender, EventArgs e) 
    { 
     if (this.ddCheckBox.Checked == false) 
     { 
      if (this.passwordtextBox.Text == "") 
      { 
       MessageBox.Show("Please enter a password!"); 
      } 
      else if (this.retypeTextBox.Text == "") 
      { 
       MessageBox.Show("Please retype password!"); 
      } 
      else if (this.passwordtextBox.Text == this.retypeTextBox.Text) 
      { 
       //details = new Details(); 
       details.SetPassword(this.passwordtextBox.Text); 

       if (this.EncryptionComboBox.Text == "AES - 128 bit" | this.EncryptionComboBox.Text == "AES - 192 bit" | this.EncryptionComboBox.Text == "AES - 256 bit") 
       { 
        this.Hide(); 

        Thread thread = null; 
        thread = new Thread(new ThreadStart(delegate() { loader.dLabel.Text = "Locking Files..."; loader.ShowDialog(); })); 
        thread.Start(); 

        details.SetEncryption(this.EncryptionComboBox.Text); 

답변

2

이 경우 System.Threading.Thread 대신 BackgroundWorker을 사용해야합니다.

+1

한 합의. 배경 작업자에게는 바로 취소 할 수있는 조항이 있습니다. –

0

는 Application.Restart() 꽤 잘 중지한다) 진지에서

을, 그래도 MSDN 웹 사이트에서이 같은 물건에 대한 정보의 톤이있다. 나는 적어도 무엇을 검색해야하는지에 대한 아이디어를 얻기 위해 이것을 사용할 것입니다. 아직 모르는 것은 아니지만 정확한 용어 (예 : 정지 vs. 취소)와 그 밖의 다른 것들을 사용하고 있는지 확인하는 데 유용한 정보가 있습니다.

http://msdn.microsoft.com/en-us/library/aa511486.aspx

취소 단추를 구현하기 위해 (이 사용되어야한다) 방법 및 배경 노동자를 시작하는 방법을 당신이 http://msdn.microsoft.com/en-us/library/ywkkz4s1.aspx 다음은 모두 멋진 자원을 찾을 선택하면

. 코드를 훔쳐서 프로그램에 연결하십시오. 희망이 도움이!

편집 : 조금 둘러보고 후, 나는 생각 당신은 MSDN 사이트에서 다음과 같이 조금 보일 것이다 호출 할 수있는 코드 :

private void Cancel_Click(object sender, EventArgs e) 
{ 
    // Cancel the asynchronous operation. 
    this.backgroundWorker1.CancelAsync(); 
} 
관련 문제