public void OnTimerEvent() { if (!OnPause && Step * DeltaTime % 1 < Tolerance) { OnTimer?.Invoke(this, new EventArgs()); } }
public override bool Update() { if (!_running) { return(false); } if (_pause) { return(true); // do NOT remove us from the list of ops to update } _remaining -= Time.deltaTime; RemainingTime.Value = _remaining; if (_remaining <= 0.0f) { OnTimer.Invoke(); if (OneShot) { return(false); } else { Start(); return(true); } } else { return(true); } }
public void DelayInvoke(int seconds, OnTimer onTimer) { var ts = DateTime.Now.Add(TimeSpan.FromSeconds(seconds)); var kv = new KeyValuePair <DateTime, OnTimer>(ts, onTimer); m_timers.Enqueue(kv); }
protected virtual void Update() { _currentTime += Time.deltaTime; OnTimer.Invoke(timer - _currentTime); OnNormalizedTimer.Invoke(_currentTime / timer); if (_currentTime >= timer) { OnTimerEnd.Invoke(); enabled = false; } }
public MainForm() { InitializeComponent(); OnTimer.Stop(); PointPersona = PrimeraPersonaPictureBox.Location; PointAscensor = AscensorPictureBox.Location; AgregarImagenes(PrimeraPersonaPictureBox, "Piso1", 9); AgregarImagenes(SegundaPersonaPictureBox, "Piso2", 4); AgregarImagenes(TerceraPersonaPictureBox, "Piso3", 4); AgregarImagenes(CuartaPersonaPictureBox, "Piso4", 4); ImagenPersona imagenPersona = new ImagenPersona { PictureBox = PrimeraPersonaPictureBox, PisoOrigen = Pisos.PrimerPiso, Id = Lista.Count() + 1, Peso = ObtenerPesoRandom() }; Lista.Add(imagenPersona); imagenPersona = new ImagenPersona { PictureBox = SegundaPersonaPictureBox, PisoOrigen = Pisos.SegundoPiso, Id = Lista.Count() + 1, Peso = ObtenerPesoRandom() }; Lista.Add(imagenPersona); imagenPersona = new ImagenPersona { PictureBox = TerceraPersonaPictureBox, PisoOrigen = Pisos.TercerPiso, Id = Lista.Count() + 1, Peso = ObtenerPesoRandom() }; Lista.Add(imagenPersona); imagenPersona = new ImagenPersona { PictureBox = CuartaPersonaPictureBox, PisoOrigen = Pisos.CuartoPiso, Id = Lista.Count() + 1, Peso = ObtenerPesoRandom() }; Lista.Add(imagenPersona); ListaBotones.Add(PrimerPisoButton); ListaBotones.Add(SegundoPisoButton); ListaBotones.Add(TercerPisoButton); ListaBotones.Add(CuartoPisoButton); }
private void DoWork() { try { OnTimer?.Invoke(this, EventArgs.Empty); } catch (Exception e) { _logger.LogError(e, "Error in timer invoke"); } _reaperTimer.Change(_timerInterval, int.MaxValue); }
public INLTimer AddTimer(string name, TimeSpan timeOffset, OnTimer callback, int loop, object userdata) { TimerItem timer = new TimerItem(); timer.Name = name; timer.Time = DateTime.Now.Add(timeOffset); timer.Delegate = callback; timer.Loop = loop; timer.UserData = userdata; timer.TimeOffset = timeOffset; m_timerList.Push(timer); return(timer); }
public INLTimer AddTimer(string name, DateTime time, OnTimer callback, object userdata) { TimerItem timer = new TimerItem(); timer.Name = name; timer.Time = time; timer.Delegate = callback; timer.Loop = 1; timer.UserData = userdata; timer.TimeOffset = new TimeSpan(0); m_timerList.Push(timer); return(timer); }
public void TimerCallback(UInt32 timer_id, UInt32 msg, UIntPtr user_ctx, UIntPtr reserve1, UIntPtr reserve2) { if (timer_id != this.TimerID) { throw new InvalidOperationException($"incoming timer id[{timer_id}] != my TimerID[{TimerID}] !!"); } TimerEventArgs arg = new TimerEventArgs(); LastTickTime = arg.SignalTime; OnTimer?.Invoke(this, arg); }
public Timer(float interval, OnTimer timer, int loopTime = -1) { m_timer = interval; m_onTimer = timer; m_loopTime = loopTime; if (loopTime == -1) { m_endless = true; } else { m_loopTime = loopTime; } }
/// <summary> /// You need to manually call this at your script Update() method /// for the timer to work properly. /// </summary> public void OnUpdate() { if (counter < 0.0f) { // Already triggered callback. } else if (counter < Length) { counter += Time.deltaTime; } else { counter = -1.0f; OnTimer.Call(); } }
private void IniciarButton_Click(object sender, EventArgs e) { if (PesoTotalTextBox.Text.ToDecimal() <= 0) { MessageBox.Show("Ingrese un peso superior a 0", "AnWil Elevadores", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } IniciarButton.Enabled = false; MoverPersonas = false; Lista = Lista.OrderBy(x => x.PisoOrigen).ToList(); PrimerPisoButton.Enabled = false; PisoActual = Pisos.PrimerPiso; PesoTotal = PesoTotalTextBox.Text.ToDecimal(); PesoTotalTextBox.Enabled = false; OnTimer.Start(); CambiarLabel("Esperando que seleccione un piso", Color.White, Color.Green); }
public void FunctionTimer() { Stopwatch watch = new Stopwatch(); watch.Start(); while (EventStopWait.Wait(Period)) { watch.Stop(); if (watch.ElapsedMilliseconds >= Period) { watch.Reset(); var arg = new TimerEventArgs(); this.LastSignalTime = arg.SignalTime; OnTimer?.Invoke(this, arg); } watch.Start(); } //multimedia }
void Tick(HeartBeatEventType eventType) { OnTimer?.Invoke(this, new HeartBeatEventArgs(eventType)); }
public MakiTimer() { timer.Elapsed += (a, b) => OnTimer?.Invoke(); }
private void TimerProc(UInt32 id, UInt32 msg, UIntPtr userCtx, UIntPtr rsv1, UIntPtr rsv2) { OnTimer?.Invoke(this, new EventArgs()); }
public Timer(OnTimer onTimer) { this.onTimer = onTimer; }
private void OnTimer_Tick(object sender, EventArgs e) { if (Lista.Sum(x => x.Peso) <= 0) { OnTimer.Stop(); } if (CapturarGente) { PesoTotalAcumulado = ListaSalida.Sum(x => x.Peso); PersonaGlobal = ObtenerImagenPorPisoControles(PisoActual) ?? new ImagenPersona(); if (PesoTotalAcumulado + PersonaGlobal.Peso >= PesoTotal) { StateTextBox.AppendText($"La persona que intento ingresar tenia {PersonaGlobal.Peso} sobrepasando el limite con {(PesoTotalAcumulado + PersonaGlobal.Peso) - PesoTotal} {Environment.NewLine}"); CambiarLabel("Ascensor Lleno.", Color.White, Color.Red); CapturarGente = false; MoverAscensor = true; ListaBotones.ForEach(x => x.Enabled = true); ObtenerButton(PisoActual).Enabled = false; } else { PersonaGlobal.PisoDireccion = AquePiso; if (PersonaGlobal.Id != 0) { if (!ListaSalida.Exists(x => x.Id == PersonaGlobal.Id)) { ListaSalida.Add(PersonaGlobal); } } else { ListaSalida.Add(new ImagenPersona() { PisoDireccion = AquePiso, Peso = 0 }); } StateTextBox.AppendText($"Peso Agregado {PersonaGlobal.Peso} {Environment.NewLine}"); CantidadPersonasLabel.Text = ListaSalida.Count(x => x.Peso > 0).ToString(); PesoElevadorLabel.Text = ListaSalida.Sum(x => x.Peso).ToString(); CapturarGente = false; MoverPersonas = true; MoverAscensor = false; CambiarLabel("Esperando que seleccione un piso", Color.White, Color.Green); } } if (MoverPersonas) { AnimarImagen(PersonaGlobal.PictureBox); if (MoverPersonaHorizontal(PersonaGlobal.PictureBox, 25)) { AsignarPosicionPersona(PersonaGlobal.PictureBox); if (PesoTotalAcumulado <= PesoTotal) { CapturarGente = false; MoverPersonas = false; if (ListaSalida.Count(x => x.PisoOrigen == PisoActual) == Lista.Count(x => x.PisoOrigen == PisoActual)) { MoverPersonas = false; MoverAscensor = true; } else { ListaBotones.ForEach(x => x.Enabled = true); ObtenerButton(PisoActual).Enabled = false; } CambiarLabel("Esperando que seleccione un piso", Color.White, Color.Green); } else { MoverPersonas = false; MoverAscensor = true; } } else { CambiarLabel("Persona en movimiento", Color.Black, Color.Yellow); } } if (MoverAscensor) { if ((int)PisoActual <= (int)AquePiso) { Pisos ppp; if (ListaSalida.Count == 0) { ppp = AquePiso; } else { ppp = ListaSalida.FirstOrDefault().PisoDireccion; } if (!MoverAscensorArriba(ppp)) { MoverPersonaVertical(ListaSalida, DecrementoEnY); MoverAscensorVertical(DecrementoEnY); CambiarLabel("Ascensor en movimiento, no presione nada", Color.White, Color.Red); } else { ListaBotones.ForEach(x => x.Enabled = true); ObtenerButton(PisoActual).Enabled = false; CambiarLabel("Esperando que seleccione un piso", Color.White, Color.Green); } } else { Pisos ppp; if (ListaSalida.Count == 0) { ppp = AquePiso; } else { ppp = ListaSalida.FirstOrDefault().PisoDireccion; } if (!MoverAscensorAbajo(ppp)) { MoverPersonaVertical(ListaSalida, DecrementoEnY); MoverAscensorVertical(DecrementoEnY); CambiarLabel("Ascensor en movimiento, no presione nada", Color.White, Color.Red); } else { ListaBotones.ForEach(x => x.Enabled = true); ObtenerButton(PisoActual).Enabled = false; CambiarLabel("Esperando que seleccione un piso", Color.White, Color.Green); } } } Invalidate(); }
public string SetTimer() { OnTimer?.Invoke(GetFirstMessage()); return(null); }
/// <summary> /// 接纳新连接,启动接收,发送,断开处理线程主体 /// </summary> public void MainLoop(object state) { int idxEngine = Convert.ToInt32(state); int numCurLoop = 0, numMaxLoop = 0; Socket socket = null; byte[] sockSendBuf = null; DuplexSocketEvent sockDup = null; UInt64 eventsOuterData = 0uL; int socketId = 0; int events = 0; byte[] sendEachBuffer = null; AsyncQueue <UInt64> eventsOuter = CommuEngine._s_CommuEngineEvents[idxEngine]; UInt64[] dataPoolOnce = new UInt64[CommuEngine.POOL_MAX_LOOP]; MinHeap <OnTimer> timerHeap = this._timerHeaps[idxEngine]; int idxBegin = idxEngine * this._ConnNumPerEngine; if (idxBegin == 0) { idxBegin = 1; } int idxEnd = (idxEngine + 1) * this._ConnNumPerEngine - 1; if (idxEnd > this._MaxConnectNum - 1) { idxEnd = this._MaxConnectNum - 1; } while (this._systemRun) { socket = null; try { numCurLoop = 0; numMaxLoop = eventsOuter.DequeueToArray(dataPoolOnce); while (numCurLoop < numMaxLoop) { eventsOuterData = dataPoolOnce[numCurLoop++]; socketId = (int)(eventsOuterData & 0x00000000FFFFFFFFL); CommuEngine._s_EventsPerSocket[socketId] |= (int)(eventsOuterData >> 32); } for (int i = idxBegin; i <= idxEnd; i++) { events = CommuEngine._s_EventsPerSocket[i]; if (events < 1) { continue; } socketId = i; CommuEngine._s_EventsPerSocket[i] = 0; sockDup = CommuEngine._s_DuplexSocketEvents[socketId]; if ((events & (int)EventType.Event_New) > 0) { #region New Connect socket = sockDup.eReceive.AcceptSocket; try { if (socket != null && !socket.ReceiveAsync(sockDup.eReceive)) { sockDup.ProcessReceive(sockDup.eReceive); } } catch (System.InvalidOperationException) { LogEngine.Write(LOGTYPE.ERROR, sockDup.SocketID.ToString(), "/s,", idxEngine.ToString(), "/idx,", sockDup.eReceive.LastOperation.ToString()); } catch (Exception ex2) { LogEngine.Write(LOGTYPE.ERROR, sockDup.SocketID.ToString(), "/s,", idxEngine.ToString(), "/idx,", ex2.Message); } OnTimer timer = new OnTimer(OnTimer.TimerHeapType.ONCE, 10 * 1000, sockDup.ConnectOnTimer); timerHeap.Push(timer); #endregion } else if ((events & (int)EventType.Event_StopCommu) > 0) { #region Stop if (sockDup.IsBreak) { continue; } try { socket = sockDup.eReceive.AcceptSocket; if (socket != null) { //socket.Shutdown(SocketShutdown.Both); socket.Close(); } } catch (Exception ex) { LogEngine.Write(LOGTYPE.ERROR, "Event_StopCommu:", ex.ToString()); } finally { sockDup.eReceive.AcceptSocket = sockDup.eSend.AcceptSocket = null; sockDup.SetBreak(); if (sockDup.BreakCallBack != null) { sockDup.BreakCallBack(sockDup.commuParam); } } #endregion } else if ((events & (int)EventType.Event_Close) > 0) { #region Close //回收 this._DuplexSocketEventPool.Push(sockDup);//second if (!sockDup.IsBreak) { LogEngine.Write(LOGTYPE.ERROR, "Get Event_StopCommu,But Target Not Break:", sockDup.SocketID.ToString(), "/sid"); } #endregion } else { sockDup = CommuEngine._s_DuplexSocketEvents[socketId]; if (sockDup.IsBreak) { continue; } //if ((events & Event_Receive) > 0) //{ // #region Receive // #endregion //} if ((events & (int)EventType.Event_SendComplet) > 0) { #region SendComplet if (sockDup.SendPool.Count > 0) { events |= (int)EventType.Event_Send; } #endregion } if ((events & (int)EventType.Event_Send) > 0) { #region 处理发放 sockSendBuf = sockDup.SendBuffer; while (sockDup.SendPool.Count > 0) { sendEachBuffer = sockDup.SendPool.First(); #region Concat bytes if (sendEachBuffer.Length <= sockSendBuf.Length) { if (sendEachBuffer.Length <= (sockSendBuf.Length - sockDup.waitSendLen)) { sendEachBuffer = sockDup.SendPool.Dequeue(); Buffer.BlockCopy(sendEachBuffer, 0, sockSendBuf, sockDup.waitSendLen, sendEachBuffer.Length); sockDup.waitSendLen += sendEachBuffer.Length; if (sockDup.waitSendLen >= CommuEngine.MTU_SEND) { break; } } else { break; } } else { sockDup.SendPool.Dequeue();//drop data //LogEngine.Write(LOGTYPE.ERROR, "ProtocolData TooLong Max:", sockSendBuf.Length.ToString(), ",", sockDup.Profile); } #endregion } #region ProcessSend if (sockDup.waitSendLen > 0) { sockDup.eSend.SetBuffer(sockSendBuf, 0, sockDup.waitSendLen); sockDup.sendBeginTicks = DateTime.Now.Ticks; socket = sockDup.eSend.AcceptSocket; try { if (socket != null && socket.Connected && !socket.SendAsync(sockDup.eSend)) { sockDup.ProcessSend(sockDup.eSend); } } catch (SocketException) { if (sockDup.eSend.SocketError == SocketError.MessageSize) { sockDup.Break(CommuBreak.SERVER_SEND_DATA_SIZE); } else { sockDup.Break(CommuBreak.SERVER_SEND_EXPECT); } } } #endregion #endregion } } } //OnTimer while (timerHeap.Count > 0 && timerHeap.Root.Weight <= DateTime.Now.Ticks) { if (timerHeap.Root.TimeOutCallBack != null) { timerHeap.Root.TimeOutCallBack(null); } if (timerHeap.Root.Type == OnTimer.TimerHeapType.ALWAYS) { timerHeap.ChangeWeight(timerHeap.Root.HeapIndex, timerHeap.Root.RefreshWeight()); } else { timerHeap.PopRoot(); } } } catch (System.Exception ex) { LogEngine.Write(LOGTYPE.ERROR, "CommuEngine MainLoop:", ex.ToString()); } finally { Thread.Sleep(1); } } }
// Вызов события таймера void Timer() { secondsAlive++; OnTimer?.Invoke(); }
private void Loop() { _nextWakeUpTickTime = Stopwatch.GetTimestamp(); try { while (true) { _nextWakeUpTickTime += _cycleTimeInTicks; while (true) { long ticks = _nextWakeUpTickTime - Stopwatch.GetTimestamp(); if (ticks <= 0L) { break; } long diff = (ticks * 1000) / Stopwatch.Frequency; // cycle in milliseconds if (diff >= 100) { Thread.Sleep(20); } else if (diff >= 40) { Thread.Sleep(10); } else if (diff >= 25) { Thread.Sleep(2); } else if (diff >= 15) { Thread.Sleep(1); } else if (diff >= 5) { Thread.SpinWait(200); } else if (diff > 1) { Thread.SpinWait(100); } else { Thread.SpinWait(10); } } long lDelay = Stopwatch.GetTimestamp() - _nextWakeUpTickTime; if (lDelay < _MaxDelayInTicks) { OnTimer?.Invoke(null, null); } else { OnSkipped?.Invoke(null, null); } } } catch (ThreadInterruptedException) { } catch (Exception) { Console.WriteLine("Exiting timer thread."); } OnStoped?.Invoke(null, null); }
protected void RaiseTimerEvent(int cyclesPerSecond) { OnTimer?.Invoke(cyclesPerSecond); }