title: I can not end a thread
body: <p>I'm trying to use Thread.Abort() but it's freezing my GUI .... It freezes all the elements except the statusLabel ... it keeps updating ... whats the problem with the code...</p>
  
  <p>I do not know why this is happening, I thought it might be the try catch block, but it is in the thread ... I believe it does not interfere with anything</p>
  
  <p>Code: </p>
  
  <p><a href="https://paste.lamlam.io/davagokeza.cs#o34Oy3vsWwK95ya0B5bk2leI8R6xweyk" rel="nofollow noreferrer">https://paste.lamlam.io/davagokeza.cs#o34Oy3vsWwK95ya0B5bk2leI8R6xweyk</a></p>
  
  <pre><code>using System;
  using System.Collections.Concurrent;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.IO;
  using System.Linq;
  using System.Net;
  using System.Text;
  using System.Threading;
  using System.Threading.Tasks;
  using System.Web;
  using System.Windows.Forms;
  
  namespace RunAsWebServer
  {
      public partial class Form1 : Form
      {
          WebServer ws;
  
          List&lt;Proxy&gt; resultList;
  
          bool continueTask = true;
  
          public Form1()
          {
              InitializeComponent();
  
              CheckForIllegalCrossThreadCalls = false;
  
              CreatServer("127.0.0.1:8080");
          }
  
  
  
          public void CreatServer(string server)
          {
              ws = new WebServer(SendResponse, "http://"+ server +"/");
              ws.Run();
          }
  
  
          public string SendResponse(HttpListenerRequest request)
          {
              var query = request.QueryString;
              var ip =  query["ip"];
              if (string.IsNullOrEmpty(ip))
              {
                  return "It's working...";
              }
              return new Whoer().Check(ip);
          }
  
          private void Form1_FormClosing(object sender, FormClosingEventArgs e)
          {
              ws.Stop();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              try
              {
                  ws.Stop();
                  CreatServer(textBox1.Text.Trim() + ":"+textBox2.Text.Trim());
  
                  MessageBox.Show("Server: " + textBox1.Text + textBox2.Text + " OK!", "Server", MessageBoxButtons.OK, MessageBoxIcon.Information);
              }
              catch (Exception ex)
              {
                  MessageBox.Show("Server: " + textBox1.Text + textBox2.Text + " Failed!", "Server", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
          }
  
          List&lt;Thread&gt; threads;
          ConcurrentQueue&lt;string&gt; queue;
  
          private void button3_Click(object sender, EventArgs e)
          {
  
              if (threads != null)
              {
                  foreach (var t in threads)
                  {
                      if (t != null)
                      {
                          if (t.IsAlive)
                          {
                              t.Abort();
                              //MessageBox.Show("Wait all threads finish" + " " +t.ManagedThreadId.ToString());
                              //return;
                          }
                      }
                  }
              }
  
              continueTask = true;
  
              toolStripStatusLabel1.Text = "Starting...";
  
              queue = new ConcurrentQueue&lt;string&gt;(File.ReadAllLines(textBox3.Text));
  
              threads = new List&lt;Thread&gt;();
  
              resultList = new List&lt;Proxy&gt;();
  
              for (int i = 0; i &lt; numericUpDown1.Value; i++)
              {
                  Thread thread = new Thread(() =&gt; {
  
                      while (continueTask)
                      {
  
                          if (queue.Count == 0)
                          {
                              continueTask = false;
                              break;
                          }
  
                          var proxy = "";
                          queue.TryDequeue(out proxy);
                          if (proxy != string.Empty)
                          {
                              try
                              {
                                  Proxy result = new Whoer().Check2(proxy);
  
                                  resultList.Add(result);
  
                                  toolStripStatusLabel1.Text = result.Ip + "|" + result.Status;
                              }
                              catch (Exception)
                              {
                                  //
                              }
                          }
                      }
  
                  });
  
                  thread.Start();
                  threads.Add(thread);
              }
  
          }
  
          private void button4_Click(object sender, EventArgs e)
          {
              List&lt;string&gt; results = new List&lt;string&gt;();
  
              foreach (var item in resultList)
              {
                  if (item != null)
                  {
                      if (item.Status.ToLower() == "live")
                      {
                          if (checkBox1.Checked)
                          {
                              if (item.IsBlackListed == "Yes" || item.IsProxy == "YES")
                                  return;
                          }
  
                          results.Add(item.ToString());
                      }
                  }
              }
  
              File.WriteAllLines("results.txt", results.ToArray());
          }
  
          private void button2_Click(object sender, EventArgs e)
          {
              var open = new OpenFileDialog()
              {
                  ValidateNames = true,
                  Filter = "Text|*.txt"
              };
  
              if(open.ShowDialog() == DialogResult.OK)
              {
                  textBox3.Text = open.FileName;
              }
          }
  
          private void button5_Click(object sender, EventArgs e)
          {
              if (threads != null)
              {
                  foreach (var t in threads)
                  {
                      if (t != null)
                      {
                          if (t.IsAlive)
                          {
                              t.Abort();
                              //MessageBox.Show("Wait all threads finish" + " " +t.ManagedThreadId.ToString());
                              //return;
                          }
                      }
                  }
              }
  
  
              //if (threads != null)
              //{
              //    continueTask = false;
  
              //    toolStripStatusLabel1.Text = "Waiting...";
              //}
          }
  
          private void Form1_Resize(object sender, EventArgs e)
          {
              if (this.WindowState == FormWindowState.Minimized)
              {
                  mynotifyicon.Visible = true;
                  mynotifyicon.ShowBalloonTip(3000);
                  this.ShowInTaskbar = false;
              }
          }
  
          private void mynotifyicon_MouseDoubleClick(object sender, MouseEventArgs e)
          {
              this.WindowState = FormWindowState.Normal;
              this.ShowInTaskbar = true;
              mynotifyicon.Visible = false;
          }
      }
  }
  </code></pre>