public void Start() { if (Running) { throw new Exception("Trying to start timer while it is already running."); } StartTime = DateTime.Now; FinishTime = null; TimerStarted?.Invoke(this, EventArgs.Empty); }
private void OnTimerStarted(TimerStarted @event) { menu.Update(mutator => { mutator.UpdateRemainingTime(@event.RemainingTime.ToTimeString()); mutator.EnableStartPomodoroItem(@event.IntervalType != IntervalType.Pomodoro); mutator.EnableStartShortBreakItem(@event.IntervalType != IntervalType.ShortBreak); mutator.EnableStartLongBreakItem(@event.IntervalType != IntervalType.LongBreak); mutator.EnableStopTimerItem(true); }); }
IEnumerator TimerCoroutine() { TimerStarted?.Invoke(TimeLeft); while (_timeLeft > 0) { yield return(new WaitForSeconds(TimerStep)); TimeLeft -= TimerStep; } EndGame(); }
protected async void Hibernate_Click(object sender, RoutedEventArgs e) { DialogWindow dialog = new DialogWindow(); bool? result = dialog.ShowDialog(); if (dialog.DialogResult == true) { TimerStarted?.Invoke(this, dialog.DWTimer); Action action = new Action(HibernateComputer); this.DataContext = dialog.DWTimer; await dialog.DWTimer.Start(action); } }
public static void StartTimer() //Метод, который должен вызываться в FixUpdate { if (_timer >= 0) { _timer -= Time.deltaTime; TimerStarted?.Invoke($"Время осталось: {Mathf.Round(_timer).ToString()}"); //Событие при старте таймера. } else { TimerStatus(); TimerEnded?.Invoke(String.Empty); //Событие при остановке таймера. } }
protected async void Restart_Click(object sender, RoutedEventArgs e) { DialogWindow dialog = new DialogWindow(); bool? result = dialog.ShowDialog(); if (dialog.DialogResult == true) { TimerStarted?.Invoke(this, dialog.DWTimer); Action action = new Action(RestartComputer); this.DataContext = dialog.DWTimer; await dialog.DWTimer.Start(action); } //Action action = new Action(() => MessageBox.Show("Timer just went off", "Restart")); //dialog.DWTimer.Start(action); }
/// <summary> /// Start the <see langword="timer" /> /// </summary> public void Start() { if (IsBusy) { throw new InvalidOperationException("Unable to start timer: it is already running"); } IsBusy = true; RemainingSeconds = Seconds; TimerStarted?.Invoke(this); for (var i = 0; i < Seconds; i++) { RemainingSeconds = Seconds - i - 1; Thread.Sleep(1000); TimerTick?.Invoke(this); } TimerFinished?.Invoke(this); IsBusy = false; }
private async void ExecuteTimer() { TimerStarted timerStarted = (name, seconds) => OutputWriteLine($"'{name}' started for {seconds} seconds."); Action <string, int> timerFinished = (name, seconds) => OutputWriteLine($"'{name}' finished."); ICutDownNotifier[] notifiers = { new NotifierByDelegate(timerStarted, timerFinished), new NotifierByLambda(timerStarted, timerFinished), new NotifierByMethod(timerStarted, timerFinished) }; notifiers[0].Init(new MyTimer.MyTimer("Чтение задания", TimerSeconds)); notifiers[1].Init(new MyTimer.MyTimer("Выполнение задания", TimerSeconds)); notifiers[2].Init(new MyTimer.MyTimer("Проверка задания перед отправкой", TimerSeconds)); foreach (var notifier in notifiers) { await Task.Run(() => notifier.Run()); } }
protected async void Shutdown_Click(object sender, RoutedEventArgs e) { DialogWindow dialog = new DialogWindow(); bool? result = dialog.ShowDialog(); if (dialog.DialogResult == true) { TimerStarted?.Invoke(this, dialog.DWTimer); Action action = new Action(ShutdownComputer); // Now once the dialog returns successfully. // We are going to pass it DWTimer object to this control's DataContext. // This will make it possible to bind to the properties of be DataContext as required. // Can you set the DataContext to the DWTimer Object?... // No.. I have forgotten most of what I read in Data Binding // // That's too bad, It's quite straight forward actually. // Now, I won't forget again this.DataContext = dialog.DWTimer; // And that does that. // Replicate it around the other methods. // Done. // Awesome. // Wait a second... // Binding it in MainView doesn't seem really useful... // MainView only contains buttons... // I have a small idea. // We create an event here, and then invoke it once we // Okay.. I am following your lead await dialog.DWTimer.Start(action); } //Action action = new Action(() => MessageBox.Show("Timer just went off", "Shutdown")); //dialog.DWTimer.Start(action); }
private void OnTimerStartedEvent() { TimerStarted?.Invoke(this, new TimerEventArgs(_timerHasEnded)); }
internal void EmitTimerStarted(IEntry <TeaTimerDefinition> entry) { TimerStarted?.Invoke(this, new TeaTimerEventArgs(entry)); }
public async void Start(string setedTime) { TimerStarted?.Invoke(); await Worker(setedTime); }
private void OnTimerStarted(TimerStarted @event) { notifyIcon.Icon = GetIcon(@event.IntervalType); }
/// <summary> /// Creates an event handler with the specified <see langword="delegates" /> /// </summary> /// <param name="timerStarted">A delegate representing a method to be executed when timer will start.</param> /// <param name="timerFinished">A delegate representing a method to be executed when timer will be finished.</param> public NotifierByDelegate(TimerStarted timerStarted, Action <string, int> timerFinished) : base(timerStarted, timerFinished) { }
protected Notifier(TimerStarted timerStarted, Action <string, int> timerFinished) { timerStartedDelegate = timerStarted; timerFinishedDelegate = timerFinished; }
/// <summary> /// Starts a new timer with the passed name and the given duration. /// Queues a <see cref="TimerStarted"/> incident and sets /// <see cref="SystemVariables.StartedTimer"/>. /// </summary> /// <param name="name">Name of the timer to start.</param> /// <param name="duration">Duration of the timer.</param> private void StartTimer(string name, float duration) { if (timers.ContainsKey(name)) { string errorMessage = string.Format("A timer named '{0}' already exists.", name); throw new ArgumentException(errorMessage); } if (duration < 0f) { duration = 0f; } Timer timer = new Timer(); timer.Name = name; timer.Duration = duration; timer.ElapsedTime = 0f; timer.IsRunning = true; timers.Add(name, timer); // ToDo: Set SystemVariable StartedTimer //SystemVariables.StartedTimer = name; TimerStarted e = new TimerStarted(); e.Name = name; e.Duration = duration; QueueEvent(e); }
private void OnTimerStarted(TimerStarted @event) { EnterState(GetRunningTimerStateFor(@event.IntervalType), @event.RemainingTime); }
/// <summary> /// Creates an event handler with the specified <see langword="delegates" /> /// </summary> /// <param name="timerStarted">A delegate representing a method to be executed when timer will start.</param> /// <param name="timerFinished">A delegate representing a method to be executed when timer will be finished.</param> public NotifierByLambda(TimerStarted timerStarted, Action <string, int> timerFinished) : base(timerStarted, timerFinished) { }