C# 使用Thread多线程,窗体关闭后进程不退出的解决方案

using System;
using System.Threading;
using System.Windows.Forms;
namespace testS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
【C# 使用Thread多线程,窗体关闭后进程不退出的解决方案】Thread myThread; //定义
private void Form1_Load(object sender, EventArgs e)
{
myThread = new Thread(new ThreadStart(s));
myThread.IsBackground = true; //设置为后台进程,这样当主线程退出时,这个线程就会退出
myThread.Start(); //启动线程
}
TY.Net.SocketsT st = new TY.Net.SocketsT();
private void s()
{
string s = TY.Net.Hostinfo.GetIP();
this.Text = s + " 11161";
st.ShowMes += new TY.Net.SocketsT.ShowMessage(showme);
st.tcpGetString(s, 11161);
}
private void showme(string m)
{
this.textBox1.AppendText(m);
}
}
}

    推荐阅读