private void TextBox_Focused() { blinkState = true; blinkTimerHandle = Application.SetInterval(() => { if (HasFocus == false) { return; } blinkState = !blinkState; Application.RequestPaint(); }, BlinkInterval); }
/// <summary> /// Schedules the given action for periodic processing by the message pump /// </summary> /// <param name="a">The action to schedule for periodic processing</param> /// <param name="interval">the execution interval for the action</param> /// <returns>A handle that can be passed to ClearInterval if you want to cancel the work</returns> public SetIntervalHandle SetInterval(Action a, TimeSpan interval) { var handle = new SetIntervalHandle(interval); Invoke(async() => { while (IsRunning && IsDrainingOrDrained == false && handle.IsExpired == false) { await Task.Delay(handle.Interval); a(); } }); return(handle); }
/// <summary> /// Updates a previously scheduled interval /// </summary> /// <param name="handle">the handle that was returned by a previous call to setInterval</param> /// <param name="newInterval">the new interval</param> public void ChangeInterval(SetIntervalHandle handle, TimeSpan newInterval) { handle.Interval = newInterval; }