기본카테고리

[C#]쓰레드 사용

DevReff 2016. 9. 10. 16:02
728x90
SMALL

private System.Threading.Thread Backup = null;

 

// 스레드 동기화 및 일시정지, 재시작

private System.Threading.ManualResetEvent _pauseEvent = new System.Threading.ManualResetEvent(false);

 

private void BTN_START_Click(object sender, EventArgs e)
{

   Backup = new System.Threading.Thread(new System.Threading.ThreadStart(Start));
   Backup.Name = "BackupFile";
   Backup.IsBackground = true;
   Backup.Start();

 

   BTN_START.Enabled = false;
   BTN_WAIT.Enabled = true;
   BTN_STOP.Enabled = true;
  }

  private void BTN_WAIT_Click(object sender, EventArgs e)
  {
   if (!IsPause)
   {
       IsPause = true;
       _pauseEvent.Reset();


    BTN_WAIT.Image = global::WooriBackup.Properties.Resources.restart;
   }
   else
   {
       IsPause = false;
       _pauseEvent.Set();

 

    BTN_WAIT.Image = global::WooriBackup.Properties.Resources.wait;
   }
  }

  private void BTN_STOP_Click(object sender, EventArgs e)
  {
      IsRunning = false;
      IsPause = false;
      _pauseEvent.Reset();
      if (Backup.IsAlive)
          Backup.Abort();

 

   BTN_START.Enabled = true;
   BTN_WAIT.Enabled = false;
   BTN_STOP.Enabled = false;
  }

 

private void Start()

{

IsRunning = true;
IsPause = false;

while(IsRunning)

{

if(IsPause)

continue;

 

...

}

}