public static ThreadPoolTimer CreatePeriodicTimer (TimeElapsedHandler handler, TimeSpan period) { if (handler == null) throw new ArgumentException ("handler"); return new ThreadPoolTimer (handler, period, isPeriodic: true); }
public void SetTimer(int MillisecondTimeout, TimeElapsedHandler CB) { lock(TimeoutList) { long Ticks = DateTime.Now.AddMilliseconds(MillisecondTimeout).Ticks; while(TimeoutList.ContainsKey(Ticks)==true) { ++Ticks; } TimeoutList.Add(Ticks,CB); if(TimeoutList.Count==1) { // First Entry mre.Reset(); handle = ThreadPool.RegisterWaitForSingleObject( mre, WOTcb, null, MillisecondTimeout, true); } else { mre.Set(); } } }
public void SetTimer(int MillisecondTimeout, TimeElapsedHandler CB) { lock (TimeoutList) { long Ticks = DateTime.Now.AddMilliseconds(MillisecondTimeout).Ticks; while (TimeoutList.ContainsKey(Ticks) == true) { ++Ticks; } TimeoutList.Add(Ticks, CB); if (TimeoutList.Count == 1) { // First Entry mre.Reset(); handle = ThreadPool.RegisterWaitForSingleObject( mre, WOTcb, null, MillisecondTimeout, true); } else { mre.Set(); } } }
/** Constructor * @param * name The name to be given to the widget (must be unique). * @param * dimensions The x Position, y Position, width, and height of the widget. * @param * positionMode The GuiMetricsMode for the values given for the position. (absolute/relative/pixel) * @param * sizeMode The GuiMetricsMode for the values given for the size. (absolute/relative/pixel) * @param * material Ogre material defining the widget image. * @param * overlayContainer associates the internal OverlayElement with a specified zOrder. * @param * ParentWidget parent widget which created this widget. */ public TextBox(string name, Vector4 dimensions, QGuiMetricsMode positionMode, QGuiMetricsMode sizeMode, string material, OverlayContainer overlayContainer, Widget ParentWidget) : base(name, dimensions, positionMode, sizeMode, material, overlayContainer, ParentWidget) { mWidgetType = Widget.WidgetType.QGUI_TYPE_TEXTBOX; mMaskUserInput = false; mBackSpaceDown = false; mBackSpaceTimer = 0.0f; mDeleteDown = false; mDeleteTimer = 0.0f; mLeftArrowDown = false; mRightArrowDown = false; mMoveCursorTimer = 0.0f; mCursorVisibilityTimer = 0.0f; mReadOnly = false; mInputMode = false; // Border Overlay gives us ability to assign material to TextBox border and Panel separately. mOverlayElement = createPanelOverlayElement(mInstanceName + ".Background", mPixelDimensions, ""); mOverlayContainer.AddChild(mOverlayElement); mOverlayElement.Show(); setMaterial(mWidgetMaterial); mCharacterHeight = 0.75f; Mogre.Vector3 textDimensions = new Mogre.Vector3(0, 0, mCharacterHeight); // Label has no material, since it directly overlaps the textbox overlay element mTextWidget = new Text(mInstanceName + ".Text", textDimensions, QGuiMetricsMode.QGUI_GMM_RELATIVE, QGuiMetricsMode.QGUI_GMM_RELATIVE, mChildrenContainer, this); mTextWidget.setTruncateMode(Text.TruncateMode.LEFT); mTextWidget.setTruncationFeedback(""); mTextWidget.setZOrderOffset(1); _addChildWidget(mTextWidget); mHorizontalAlignment = GuiHorizontalAlignment.GHA_LEFT; mVerticalAlignment = GuiVerticalAlignment.GVA_CENTER; alignText(mHorizontalAlignment, mVerticalAlignment); OnDeactivate += new DeactivateEventHandler(TextBox_OnDeactivate); OnCharacter += new CharacterEventHandler(TextBox_OnCharacter); OnKeyDown += new KeyDownEventHandler(TextBox_OnKeyDown); OnKeyUp += new KeyUpEventHandler(TextBox_OnKeyUp); OnMouseButtonDown += new MouseButtonDownEventHandler(TextBox_OnMouseButtonDown); OnTimeElapsed += new TimeElapsedHandler(TextBox_OnTimeElapsed); }
private void HandleTimer(Object State, bool TimedOut) { ArrayList TriggerList = new ArrayList(); lock (TimeoutList) { while (TimeoutList.Count > 0) { DateTime timeout = new DateTime((long)TimeoutList.GetKey(0)); TimeElapsedHandler cb = (TimeElapsedHandler)TimeoutList.GetByIndex(0); if (DateTime.Now.CompareTo(timeout) >= 0) { // Trigger TriggerList.Add(cb); TimeoutList.RemoveAt(0); } else { // Reset timer mre.Reset(); int MillisecondTimeout = (int)new TimeSpan(timeout.Ticks - DateTime.Now.Ticks).TotalMilliseconds; if (MillisecondTimeout <= 0) { mre.Set(); MillisecondTimeout = 0; } handle = ThreadPool.RegisterWaitForSingleObject( mre, WOTcb, null, MillisecondTimeout, true); break; } } } foreach (TimeElapsedHandler _cb in TriggerList) { _cb(this); } }
private ThreadPoolTimer (TimeElapsedHandler handler, TimeSpan delay, bool isPeriodic) { Delay = delay; if (isPeriodic) Period = delay; this.handler = handler; this.realTimer = new Timer (t => { var ltimer = (ThreadPoolTimer)t; if (!ltimer.isCanceled) { Task.Factory.StartNew (o => { ThreadPoolTimer taskedTimer = (ThreadPoolTimer)o; taskedTimer.handler (taskedTimer); }, ltimer); } }, this, (int)delay.TotalMilliseconds, (isPeriodic) ? (int)delay.TotalMilliseconds : Timeout.Infinite); }
public static ThreadPoolTimer CreateTimer (TimeElapsedHandler handler, TimeSpan delay) { if (handler == null) throw new ArgumentException ("handler"); return new ThreadPoolTimer (handler, delay, isPeriodic: false); }