/// <summary> /// 启动服务。 /// </summary> protected override void OnStart(string[] args) { #if DEBUG Debugger.Launch(); //Launches and attaches a debugger to the process. #endif try { this._eventLog.WriteEntry("MES.ImageDataTransfer 服务启动"); if (lstWrapper == null) { lstWrapper = new List <ImageDataTransferThreadWrapper>(); } //获取配置节信息 this._section = (ImageConfigurationSection)ConfigurationManager.GetSection("mes.image"); //增加线程个数。 foreach (ImageDeviceElement element in this._section.Devices) { ParameterizedThreadStart threadStart = new ParameterizedThreadStart(TransferData); ImageDataTransferThreadWrapper wrapper = new ImageDataTransferThreadWrapper(element, threadStart); lstWrapper.Add(wrapper); } //启动线程。 foreach (ImageDataTransferThreadWrapper wrapper in lstWrapper) { Thread.Sleep(500); wrapper.Start(); } } catch (Exception ex) { this._eventLog.WriteEntry(string.Format("MES.ImageDataTransfer:{0}", ex.Message), EventLogEntryType.Error); } }
/// <summary> /// 数据转置 /// </summary> private void TransferData(ImageDataTransferThreadWrapper wrapper) { while (wrapper.Loop) { try { DateTime dtStartTime = DateTime.Now; ImageDataTransferAction sdgData = new ImageDataTransferAction(); sdgData.Execute(wrapper.Device); DateTime dtEndTime = DateTime.Now; if (sdgData.TransferCount > 0) { string msg = string.Format("MES.ImageDataTransfer:开始时间:{0};结束时间:{1};耗用时间:{2}秒;转置 {4} 设备数据数量:{3}。", dtStartTime , dtEndTime , (dtEndTime - dtStartTime).TotalSeconds , sdgData.TransferCount , wrapper.Device.Name); this._eventLog.WriteEntry(msg); } } catch (Exception ex) { this._eventLog.WriteEntry(ex.Message, EventLogEntryType.Error); } if (wrapper.Loop) { Thread.Sleep(1000); } } wrapper.AutoResetEvent.Set(); }
private void btnStart_Click(object sender, EventArgs e) { try { //取得刷新时间间隔 if (int.TryParse(txtInterval.Text, out nSecond) == true) { if (nSecond < 1) { MessageBox.Show("刷新时间设置不能小于1秒!"); return; } } //转换为毫秒并记录在窗体全局变量中 nSecond = nSecond * 1000; //??? if (lstWrapper == null) { lstWrapper = new List <ImageDataTransferThreadWrapper>(); } dataTransferAction.OnDataTransferFinished += new EventHandler <DataTransferFinishedArgs>(DataTransferFinished); //获取配置节信息 this._section = (ImageConfigurationSection)ConfigurationManager.GetSection("mes.image"); // initialize tokens IntPtr pExistingTokenHandle = new IntPtr(0); IntPtr pDuplicateTokenHandle = new IntPtr(0); //创建FTP对象 //dataTransferAction.CreateFTPManager("", "",""); //增加线程个数。 foreach (ImageDeviceElement element in this._section.Devices) { ParameterizedThreadStart threadStart = new ParameterizedThreadStart(TransferData); ImageDataTransferThreadWrapper wrapper = new ImageDataTransferThreadWrapper(element, threadStart); lstWrapper.Add(wrapper); } //启动线程。 foreach (ImageDataTransferThreadWrapper wrapper in lstWrapper) { StartTransfer(); //Thread.Sleep(nSecond); wrapper.Start(); } } catch (Exception ex) { } }
/// <summary> /// 启动数据传递 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, EventArgs e) { try { //取得计数器间隔 if (int.TryParse(txtInterval.Text, out nSecond) == true) { if (nSecond < 1) { MessageBox.Show("时间设置不能小于(1)秒"); return; } } nSecond = nSecond * 1000; if (lstWrapper == null) { lstWrapper = new List <ImageDataTransferThreadWrapper>(); } dataTransferAction.OnDataTransferFinished += new EventHandler <DataTransferFinishedArgs>(DataTransferFinished); //获取配置节信息 this._section = (ImageConfigurationSection)ConfigurationManager.GetSection("mes.image"); //增加线程个数。 foreach (ImageDeviceElement element in this._section.Devices) { ParameterizedThreadStart threadStart = new ParameterizedThreadStart(TransferData); ImageDataTransferThreadWrapper wrapper = new ImageDataTransferThreadWrapper(element, threadStart); lstWrapper.Add(wrapper); } //启动线程 foreach (ImageDataTransferThreadWrapper wrapper in lstWrapper) { StartTransfer(); Thread.Sleep(nSecond); wrapper.Start(); } } catch (Exception ex) { //显示错误日志信息 richTextBox1.Text = ex.Message + "\n" + richTextBox1.Text; } }
/// <summary> /// 数据转置 /// </summary> private void TransferData(object obj) { try { ImageDataTransferThreadWrapper wrapper = obj as ImageDataTransferThreadWrapper; if (wrapper == null) { return; } TransferData(wrapper); } catch (Exception ex) { } }
/// <summary> /// 数据转置 /// </summary> private void TransferData(object obj) { try { ImageDataTransferThreadWrapper wrapper = obj as ImageDataTransferThreadWrapper; if (wrapper == null) { return; } TransferData(wrapper); } catch (Exception ex) { this._eventLog.WriteEntry("MES.ImageDataTransfer: " + ex.Message); } }
/// <summary> /// 数据转置 /// </summary> private void TransferData(ImageDataTransferThreadWrapper wrapper) { while (wrapper.Loop) { try { DateTime dtStartTime = DateTime.Now; dataTransferAction.Execute(wrapper.Device); DateTime dtEndTime = DateTime.Now; if (dataTransferAction.TransferCount > 0) { } } catch (Exception ex) { } if (wrapper.Loop) { Thread.Sleep(nSecond); } } wrapper.AutoResetEvent.Set(); }