多线程 以及 主程序退出时 子线程的销毁

            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();

 

posted on 2018-06-21 16:20  陈德洲  阅读(322)  评论(0编辑  收藏  举报

导航