Advertisement
Guest User

Wurm Status Server | Sophorino | Thread related

a guest
Mar 11th, 2015
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. Thread t;
  2.  
  3. private void button1_Click(object sender, EventArgs e) {
  4.     button1.Enabled = false;
  5.     //
  6.  
  7.     t = new Thread(new ThreadStart(_testlog));
  8.     t.IsBackground = true;
  9.     t.Start();
  10.  
  11.     //
  12.  
  13.     button2.Enabled = true;
  14. }
  15.  
  16. private void button2_Click(object sender, EventArgs e) {
  17.     button2.Enabled = false;
  18.  
  19.     //
  20.  
  21.     if (t.IsAlive) {
  22.         t.Abort();
  23.     }
  24.  
  25.     //
  26.  
  27.     button1.Enabled = true;
  28. }
  29.  
  30. public void _log(RichTextBox richTextBox, String msg) {
  31.     if (richTextBox.InvokeRequired) {
  32.         richTextBox.BeginInvoke(new Action(delegate {
  33.             _log(richTextBox, msg);
  34.         }));
  35.         return;
  36.     }
  37.  
  38.     richTextBox1.AppendText(msg + "\n");
  39. }
  40.  
  41. public void _testlog() {
  42.     while (true) {
  43.         _log(richTextBox1, "Test");
  44.         Thread.Sleep(5000);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement