static void Main(string[] args) { TimeHandle timeHandle = new TimeHandle(); timeHandle.SetAction(() => { Console.WriteLine("{0} 456", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); }); timeHandle.StartTimeSpanSchedule(2); Thread.Sleep(20000); timeHandle.StopSchedule(); Console.ReadKey(); }
public void SetUp() { tsource = new MockTimeSource(); handle = new TimeHandle(tsource, new MockTimeSink()); tester = new ThreadSyncTester(); sourceThread = tester.ObtainThread("source"); sinkThread = tester.ObtainThread("sink"); externalThread = tester.ObtainThread("external"); interval = TimeInterval.FromTicks(1000); SetSourceSideActiveOnExternal(true); }
/// <summary> /// 时间控制器 /// </summary> /// <param name="timeIntvral"></param> 每隔几秒执行一次 /// <param name="maxTime"></param> 最多执行几秒 /// <param name="isFinsh"></param> 循环执行开关 true 不再循环 /// <param name="timeHandle"></param> 循环执行方法 /// <param name="timeOutHandle"></param> 循环超时方法 public static void Handle(int timeIntvral, int maxTime, ref bool isFinsh, TimeHandle timeHandle, TimeOutHandle timeOutHandle) { int initTime = 0; while ((maxTime > initTime) && (!isFinsh)) // '循环等待 { timeHandle(); // '转让控制权,以便让操作系统处理其它的事件。 Thread.Sleep(1000 * timeIntvral); initTime += timeIntvral; } if (!isFinsh) { timeOutHandle(); } }
public UploadRecord(Trial trial, Color bkColor, Form fm, FolderBrowserDialog dialog, Socket sock) { this.trial = trial; InitializeComponent(); BackColor = bkColor; this.bkColor = bkColor; parent = (FmMain)fm; dnldDialog = dialog; dnldSock = sock; labPltfm.Text = trial.TrPltfmName; labPdct.Text = trial.TrPdctName; labDate.Text = TimeHandle.milSecondsToDatetime(long.Parse(trial.TrDate)).ToString(); labInfo.Text = trial.TrInfo; link = EnDeCode.encodeLink(trial.TrUserId + "_" + trial.TrDate); }
public MyTrial(Trial trial, FmMain fm) { InitializeComponent(); fmMain = fm; this.trial = trial; if (FmMain.userDict == null && FmMain.userDict.Count == 0) { btUser.Text = trial.TrUserId; } else { btUser.Text = FmMain.userDict[trial.TrUserId]; } labTrialInfo.Text = trial.TrInfo; labTrialDate.Text = TimeHandle.milSecondsToDatetime(long.Parse(trial.TrDate)).ToString(); trialUniqStr = trial.TrUserId + "_" + trial.TrDate; fileName = trialUniqStr + ".csv"; }
private void btUpld_Click(object sender, EventArgs e) { if (!groupInfo.Visible) { MessageBox.Show("Trial info not exist!", "error"); return; } else { StringBuilder sb = new StringBuilder(); sb.Append("activator:" + trialInfo.Activator + "\n"); sb.Append("operator:" + trialInfo.Operator + "\n"); sb.Append("pltfm:" + trialInfo.Pltfm + "\n"); sb.Append("pdct:" + trialInfo.Pdct + "\n"); sb.Append("unique:" + trialInfo.Unique + " " + TimeHandle.milSecondsToDatetime(long.Parse(trialInfo.Unique.Split('_')[1])) + "\n"); sb.Append("info:" + trialInfo.Info + "\n"); sb.Append("other:" + trialInfo.Other + "\n"); //组装上传请求头 upldHead = "upld:#"; upldHead += trialInfo.Activator + "#" + trialInfo.Operator + "#" + trialInfo.Unique + "#" + trialInfo.Pltfm + "#" + trialInfo.Pdct + "#" + trialInfo.Info + "#" + trialInfo.Other + "#"; MyLogger.WriteLine("upldhead:" + upldHead); //return; //发送上传请求头 try { upldSock.Send(Encoding.UTF8.GetBytes(upldHead.ToCharArray())); MyLogger.WriteLine("client upldSock 发送了请求头:" + upldHead); } catch { upldRunFlg = false; // 中断上面的recvTh 线程 MessageBox.Show("与服务端断开连接!", "message"); MyLogger.WriteLine("-------upldSock 发送消息头时 遇到异常--------"); } } }
private bool BeginConnect(int maxConnectNum) { this._timerTrigger = new MinHeap <SocketClientInfo>(maxConnectNum); string[] aryIPPort = tb_IPPort.Text.Split(':'); this.m_strIP = aryIPPort[0]; this.m_nPort = Convert.ToInt32(aryIPPort[1]); for (int i = 0; i < maxConnectNum; i++) { SocketClient client = new SocketClient(3 * m_nMinReceiveSize, 2 * m_nMinSendSize, m_strIP, m_nPort); client.eventPrintMessage += new EventHandler <SessionEventArgs>(this.OnEventPrintMessage); client.parent = this; SocketClientInfo socketClientInfo = new SocketClientInfo(); socketClientInfo.timeOutCallBack = client.TimerHandle; socketClientInfo.Weight = TimeHandle.ConvertDatetimeToSec(DateTime.Now) + socketClientInfo.timeSpan; this._timerTrigger.Push(socketClientInfo); } ThreadHandle.StartBackgroundThread(new ThreadStart(this.MainLoop), null); return(true); }
private void MainLoop() { while (Interlocked.Read(ref this.m_lngRun) > 0) { try { UInt32 timestamp = TimeHandle.ConvertDatetimeToSec(DateTime.Now); if (this._timerTrigger.Count > 0 && this._timerTrigger.Root.Weight <= timestamp) { this._timerTrigger.Root.timeOutCallBack(); this._timerTrigger.ChangeWeight(this._timerTrigger.Root.HeapIndex, timestamp + this._timerTrigger.Root.timeSpan); } } catch { } finally { Thread.Sleep(10); } } }
private void btSure_Click(object sender, EventArgs e) { foreach (Control con in infos) { if (con == null || con.Text.Equals("")) { MessageBox.Show("Trail info not complete!", "error"); return; } } if (isNewUpld) //新的上传 { string uid = getUidByName(teamUserDict, combActivator.Text); if (uid != null) { trialInfo.Activator = uid; } else { this.DialogResult = DialogResult.Cancel; MessageBox.Show("Cant get Activator userid!", "error!"); return; } } else //旧的上传 { trialInfo.Activator = combActivator.Text.Trim(); } trialInfo.Operator = combOperator.Text; trialInfo.Pltfm = combPltfm.Text; trialInfo.Pdct = combPdct.Text; trialInfo.Info = txtInfo.Text.Trim(); trialInfo.Other = txtOther.Text.Trim(); if (trialInfo.Info.Equals("")) { if (isNewUpld) { trialInfo.Info = combActivator.Text + "'s trial info"; } else { trialInfo.Info = combActivator.Text + "'s overupload"; } } if (trialInfo.Other.Equals("")) { if (isNewUpld) { trialInfo.Other = combActivator.Text + "'s trial other"; } else { trialInfo.Other = combActivator.Text + "'s overupload other"; } } if (isNewUpld) { trialInfo.Unique = trialInfo.Activator + "_" + TimeHandle.datetimeToMilSeconds(DateTime.Now); } this.DialogResult = DialogResult.OK; this.Dispose(); }
public void ReportTimeProgress(TimeHandle h, TimeInterval diff) { }
public bool UnblockHandle(TimeHandle h) { UnblockCounter++; return(true); }