protected void Timer2_Tick(object sender, EventArgs e) { IDataBase db = DBAccess.CreateDb(); //创建DataBase类对象 string GridView1Str = "select Longth from Paper where PaperID='" + Session["PaperID"] + "'"; //查询该账号数据库是否存在 int count = (db.GetRecordCount(GridView1Str)) * 60; if (ViewState["count"] != null) { count = (int)ViewState["count"]; } count--; ViewState["count"] = count; Label31.Text = count.ToString(); if (count == 0) { //SubmitBind(); Timer2.Enabled = false; IObserver observer = this; //指定观察者 ITimer timerManagement = new TimerManagement(); //实例化抽象目标类 timerManagement.Add(observer); //给抽象目标添加观察者 timerManagement.SavePaper(); //目标类实现通知方法,即让页面提交保存 Response.Redirect("/student/answer.aspx"); //Response.Write("<script>alert('时间到,系统已自动提交试卷')</script>"); } }
public new void StartStack() { ContTimer_Sync = 0; // Se activa el timer para pedir datos TimerManagement.Interval = TIMER_STATUS_TIME; TimerManagement.AutoReset = false; // se debe activar de nuevo al salir del evento Elapsed TimerManagement.Start(); }
//Private Sub LoadAllToolTemps() // 'leer temperaturas de selección y niveles. Se usa al cambier el mÃnimo o máximo de la estación // For index = 0 To Info_Port.Length - 1 // ReadSelectTemp(CType(index, cPort)) // For Each ToolIn As cls_ToolSettings In Info_Port(0).ToolParam.ToolSettings // If ToolIn.Tool <> GenericStationTools.NOTOOL Then // ReadLevelsTemps(CType(index, cPort), ToolIn.Tool) // End If // Next // Next //End Sub #endregion #region Timers and Events public async void TimerStatus_Tick(object sender, System.EventArgs e) { //SyncLock LockTimer02 // dentro de un try, porque se puede haber producido la desconexión de la estación // y haberse borrado las clases y threads correpondientes try { if (connectErrorStatus != EnumConnectError.NO_ERROR) { return; } // el UpdateStationStatus se usa para sincronismo if (ContTimer_Sync > (TIMER_SYNC_COUNT - 1)) { await UpdateStationStatusAsync(); // obtener datos de modo continuo ContTimer_Sync = 0; } else { ContTimer_Sync++; } if (bSendCommandsFirstTime) { // primera solicitud de todos los valores await LoadStationParamAsync(); await LoadAllToolParamAsync(); await LoadAllPortStatusAsync(); await LoadAllPeripheralAsync(); await LoadAllCountersAsync(); await LoadEthernetConfigurationAsync(); await LoadRobotConfigurationAsync(); bSendCommandsFirstTime = false; } } catch (Exception) { } // se vuelve a activar if (TimerManagement != null) { TimerManagement.Start(); } //End SyncLock }
public ThrottledManualResetEventSlim(TimeSpan?throttlingInterval, bool initialState = false, TimerManagement timerManagement = TimerManagement.Automatic, CancellationToken token = default) { _throttlingInterval = throttlingInterval; _mre = new ManualResetEventSlim(initialState); _timerManagement = timerManagement; _token = token; switch (_timerManagement) { case TimerManagement.Automatic: StartThrottling(); break; case TimerManagement.Manual: break; default: throw new ArgumentException($"Unsupported throttling management: {_timerManagement}"); } }