void prog_close() { if (list_clients != null) { foreach (DdeClient dc in list_clients) { try { if (dc.IsConnected) { dc.Disconnect(); dc.Dispose(); } } catch (Exception ex) { this.Invoke((MethodInvoker)(() => lbMsg.Items.Add(DateTime.Now.ToString("HH:mm:ss") + " prog_close-" + ex.Message))); } } } list_clients.Clear(); if (DDEServer != null) { try { DDEServer._ThreadTimer.Dispose(); DDEServer.Disconnect(); DDEServer.Dispose(); } catch { } } DDEServer = null; try { if (tempHashTable.Count > 0) { foreach (WebDownload wd in tempHashTable) { GC.SuppressFinalize(wd); } } } catch { } }
void dde_start() { this.Invoke((MethodInvoker)(() => UIreadonly())); setup_dde(); try { if (DDEServer != null) { DDEServer.Dispose(); } DDEServer = new MyServer(txtServer.Text, txtTopic.Text, ref sendData); DDEServer.UpdateMsg += LogMsg; myTopic = txtTopic.Text; this.Invoke((MethodInvoker)(() => lbMsg.Items.Add(DateTime.Now.ToString("HH:mm:ss") + " 開始......"))); GC.KeepAlive(DDEServer); GC.KeepAlive(list_clients); } catch (Exception ex) { this.Invoke((MethodInvoker)(() => lbMsg.Items.Add(DateTime.Now.ToString("HH:mm:ss") + " dde_start fail:" + ex.ToString()))); } }