多线程 以及 主程序退出时 子线程的销毁
this.ClientThread=new Thread(SocketClientThread); this.ClientThread.Start(DevByteStreamQueue);
线程创建
线程函数定义及实现:
static void SocketClientThread(object o) { string IP, Port; try { IP = ConfigurationManager.AppSettings["LocalServerIP"]; Port = ConfigurationManager.AppSettings["LocalServerPort"]; } catch (Exception ex) { LogManager.GetLogger("Error").Error(ex.Message); return; } Queue<byte[]> DevByteStreamQueue = o as Queue<byte[]>; ... ... ... }
主线程退出时销毁子线程:
session.ClientThread.Abort();
session.ClientThread.DisableComObjectEagerCleanup();