public void stop() { running = false; startTime = 0; currentCount = 0; onTimer = null; onComplete = null; Dispose(); }
public void stop() { this.running = false; this.startTime = 0L; this.currentCount = 0; this.onTimer = null; this.onComplete = null; this.Dispose(); }
public TimerProperties(TimerHandle timerHandle) { InitializeComponent(); _timerHandle = timerHandle; _timerHandle.Reference(); this.UpdateInfo(); }
//获取结果的回调方法 public void ResultReturns(IAsyncResult iar) { //将状态对象转换为委托类型 TimerHandle del = (TimerHandle)iar.AsyncState; //调用委托的EndInvoke方法获取结果 //int result = del.EndInvoke(del); //显示结果 //Console.WriteLine("Delegate returned result: {0}"); }
private string getTimerString(TimerHandle th) { string pattern = "<size=13>Status:<color={0}>{1}</color>\tTag:{2} </size>"; return(string.Format(pattern, th.bPaused? "red" : "green", th.bPaused? "Paused":"Running", th.tag )); }
private TimerHandle RegisterHandle(TimerHandle handle) { for (int i = 0; i < RegisteredTimers.Count; ++i) { TimerHandle iHandle = RegisteredTimers[i]; if (iHandle.ExecuteAt > handle.ExecuteAt) { RegisteredTimers.Insert(i, handle); return handle; } } RegisteredTimers.Add(handle); return handle; }
public IEnumerator TimerStopsCorrectly() { int id = 0; TimerHandle targetTimerHandle = _timerService.StartTimer(delegate { id++; }, 0.15f); _timerService.StartTimer(delegate { _timerService.StopTimer(in targetTimerHandle); }, 0.05f);
public IEnumerator TimerLoopsCorrectly() { int id = 0; TimerHandle timerHandle = _timerService.StartTimer(delegate { id++; }, 0, 0.01f, 5); yield return(new WaitForSeconds(0.1f)); Assert.That(id == 5); Assert.That(!_timerService.IsTimerActive(in timerHandle)); }
public static TimerHandle AddTimer(this MonoBehaviour mb, TimerFunc func, float delay, float interval, int maxCount, string tag = "defaultTag") { TimerHandle th = new TimerHandle(); th.func = func; th.delay = delay; th.interval = interval; th.maxCount = maxCount; th.tag = tag; mb.StartCoroutine(_timer(th)); return(th); }
public ProviderThread(int interval) { LinkedList.InitializeListHead(_listHead); _timerHandle = TimerHandle.Create(TimerAccess.All, TimerType.SynchronizationTimer); this.Interval = interval; _thread = new Thread(new ThreadStart(this.Update), ProcessHacker.Common.Utils.QuarterStackSize); _thread.IsBackground = true; _thread.SetApartmentState(ApartmentState.STA); _thread.Start(); _thread.Priority = ThreadPriority.Lowest; _initializedEvent.Wait(); }
private static IEnumerator _timer(TimerHandle th) { int countNow = 0; if (th.delay > 0f) { yield return(new WaitForSeconds(th.delay)); } while (th.maxCount != 0) { if (th.bDead == true) { break; } if (th.bPaused == true) { yield return(0); } else { if (th.maxCount != Timer.INFINITE) { ++countNow; } #if UNITY_EDITOR ++th.countNow; #endif if (th.func()) //If TimerFunc return true then end Timer Immediately. { break; } if (th.maxCount != Timer.INFINITE && countNow >= th.maxCount) { break; } yield return(new WaitForSeconds(th.interval)); } } //clean up timer th.bDead = true; if (th.completeCB != null) { th.completeCB(); } }
public ITimer StartTimer(long timestamp, FAction callback) { if (now < 0) { throw new TimerException("StartTimer before first update."); } if (timestamp < now) { throw new TimerException("Timer timeout before now."); } var timer = new TimerHandle(this, timestamp, callback); var id = timestamp / robinTime; var queue = timers.GetValueOrAdd(id); queue.Add(timer); return(timer); }
public static void ShowHandleProperties(SystemHandleEntry handleInfo) { try { IntPtr handle = new IntPtr(handleInfo.Handle); ProcessHandle phandle = new ProcessHandle(handleInfo.ProcessId, ProcessAccess.DupHandle); GenericHandle dupHandle = null; // Try to get a handle, since we need one for security editing. try { dupHandle = new GenericHandle(phandle, handle, 0); } catch { } PropSheetHeader64 header = new PropSheetHeader64 { dwSize = (uint)PropSheetHeader64.SizeOf, nPages = 2, dwFlags = (uint)PropSheetFlags.PSH_DEFAULT, pszCaption = "Handle Properties" }; using (HandleDetails hw = new HandleDetails()) { hw.ObjectHandle = handleInfo; hw.HandlePropertiesCallback += (control, name, typeName) => { switch (typeName.ToLowerInvariant()) { // Objects with separate property windows: case "file": case "job": case "key": case "token": case "process": { Button b = new Button { FlatStyle = FlatStyle.System, Text = "Properties" }; b.Click += (sender, e) => { try { switch (typeName.ToLowerInvariant()) { case "file": { FileUtils.ShowProperties(name); } break; case "job": { dupHandle = new GenericHandle(phandle, handle, (int)JobObjectAccess.Query); (new JobWindow(JobObjectHandle.FromHandle(dupHandle))).ShowDialog(); } break; case "key": { try { PhUtils.OpenKeyInRegedit(PhUtils.GetForegroundWindow(), name); } catch (Exception ex) { PhUtils.ShowException("Unable to open the Registry Editor", ex); } } break; case "token": { using (TokenWindow twindow = new TokenWindow(new RemoteTokenHandle(phandle, handle))) { twindow.ShowDialog(); } } break; case "process": { dupHandle = new GenericHandle(phandle, handle, (int)OSVersion.MinProcessQueryInfoAccess); int pid = ProcessHandle.FromHandle(dupHandle).ProcessId; Program.GetProcessWindow(Program.ProcessProvider.Dictionary[pid], Program.FocusWindow); } break; } } catch (Exception ex) { PhUtils.ShowException("Unable to show object properties", ex); } }; control.Controls.Add(b); } break; case "event": { dupHandle = new GenericHandle(phandle, handle, (int)EventAccess.QueryState); var eventProps = new EventProperties(EventHandle.FromHandle(dupHandle)); control.Controls.Add(eventProps); } break; case "eventpair": { dupHandle = new GenericHandle(phandle, handle, (int)EventPairAccess.All); var eventPairProps = new EventPairProperties(EventPairHandle.FromHandle(dupHandle)); control.Controls.Add(eventPairProps); } break; case "mutant": { dupHandle = new GenericHandle(phandle, handle, (int)MutantAccess.QueryState); var mutantProps = new MutantProperties(MutantHandle.FromHandle(dupHandle)); control.Controls.Add(mutantProps); } break; case "section": { dupHandle = new GenericHandle(phandle, handle, (int)SectionAccess.Query); var sectionProps = new SectionProperties(SectionHandle.FromHandle(dupHandle)); control.Controls.Add(sectionProps); } break; case "semaphore": { dupHandle = new GenericHandle(phandle, handle, (int)SemaphoreAccess.QueryState); var semaphoreProps = new SemaphoreProperties(SemaphoreHandle.FromHandle(dupHandle)); control.Controls.Add(semaphoreProps); } break; case "timer": { dupHandle = new GenericHandle(phandle, handle, (int)TimerAccess.QueryState); var timerProps = new TimerProperties(TimerHandle.FromHandle(dupHandle)); control.Controls.Add(timerProps); } break; case "tmrm": { dupHandle = new GenericHandle(phandle, handle, (int)ResourceManagerAccess.QueryInformation); var tmRmProps = new TmRmProperties(ResourceManagerHandle.FromHandle(dupHandle)); control.Controls.Add(tmRmProps); } break; case "tmtm": { dupHandle = new GenericHandle(phandle, handle, (int)TmAccess.QueryInformation); var tmTmProps = new TmTmProperties(TmHandle.FromHandle(dupHandle)); control.Controls.Add(tmTmProps); } break; } }; hw.Init(); IntPtr[] pages = new IntPtr[2]; pages[0] = hw.CreatePageHandle(); pages[1] = CreateSecurityPage(SecurityEditor.EditSecurity2( null, SecurityEditor.GetSecurableWrapper(dupHandle), hw._name, NativeTypeFactory.GetAccessEntries(NativeTypeFactory.GetObjectType(hw._typeName)) )); GCHandle gch = GCHandle.Alloc(pages, GCHandleType.Pinned); header.phpage = gch.AddrOfPinnedObject(); PropertySheetW(ref header); if (dupHandle != null) { dupHandle.Dispose(); } } } catch (Exception ex) { PhUtils.ShowException("Unable to show handle properties", ex); } }
public void ClearTimeout(TimerHandle handle) { UnregisterHandle(handle); }
public void Initialize(TimerHandle handle, Action action, object state) { this.handle = handle; this.action = action; this.state = state; }
public static void ShowHandleProperties(SystemHandleEntry handleInfo) { try { HandlePropertiesWindow window = new HandlePropertiesWindow(handleInfo); IntPtr handle = new IntPtr(handleInfo.Handle); ProcessHandle phandle = new ProcessHandle(handleInfo.ProcessId, ProcessAccess.DupHandle); GenericHandle dupHandle = null; window.HandlePropertiesCallback += (control, name, typeName) => { switch (typeName.ToLowerInvariant()) { // Objects with separate property windows: case "file": case "job": case "key": case "token": case "process": { Button b = new Button(); b.FlatStyle = FlatStyle.System; b.Text = "Properties"; b.Click += (sender, e) => { try { switch (typeName.ToLowerInvariant()) { case "file": { FileUtils.ShowProperties(name); } break; case "job": { dupHandle = new GenericHandle( phandle, handle, (int)JobObjectAccess.Query); (new JobWindow(JobObjectHandle.FromHandle(dupHandle))).ShowDialog(); } break; case "key": { try { PhUtils.OpenKeyInRegedit(PhUtils.GetForegroundWindow(), name); } catch (Exception ex) { PhUtils.ShowException("Unable to open the Registry Editor", ex); } } break; case "token": { (new TokenWindow(new RemoteTokenHandle(phandle, handle))).ShowDialog(); } break; case "process": { int pid; if (KProcessHacker.Instance != null) { pid = KProcessHacker.Instance.KphGetProcessId(phandle, handle); } else { dupHandle = new GenericHandle( phandle, handle, (int)OSVersion.MinProcessQueryInfoAccess); pid = ProcessHandle.FromHandle(dupHandle).GetProcessId(); } Program.GetProcessWindow(Program.ProcessProvider.Dictionary[pid], (f) => Program.FocusWindow(f)); } break; } } catch (Exception ex) { PhUtils.ShowException("Unable to show object properties", ex); } }; control.Controls.Add(b); } break; case "event": { dupHandle = new GenericHandle(phandle, handle, (int)EventAccess.QueryState); var eventProps = new EventProperties(EventHandle.FromHandle(dupHandle)); control.Controls.Add(eventProps); } break; case "eventpair": { dupHandle = new GenericHandle(phandle, handle, (int)EventPairAccess.All); var eventPairProps = new EventPairProperties(EventPairHandle.FromHandle(dupHandle)); control.Controls.Add(eventPairProps); } break; case "mutant": { dupHandle = new GenericHandle(phandle, handle, (int)MutantAccess.QueryState); var mutantProps = new MutantProperties(MutantHandle.FromHandle(dupHandle)); control.Controls.Add(mutantProps); } break; case "section": { dupHandle = new GenericHandle(phandle, handle, (int)SectionAccess.Query); var sectionProps = new SectionProperties(SectionHandle.FromHandle(dupHandle)); control.Controls.Add(sectionProps); } break; case "semaphore": { dupHandle = new GenericHandle(phandle, handle, (int)SemaphoreAccess.QueryState); var semaphoreProps = new SemaphoreProperties(SemaphoreHandle.FromHandle(dupHandle)); control.Controls.Add(semaphoreProps); } break; case "timer": { dupHandle = new GenericHandle(phandle, handle, (int)TimerAccess.QueryState); var timerProps = new TimerProperties(TimerHandle.FromHandle(dupHandle)); control.Controls.Add(timerProps); } break; case "tmrm": { dupHandle = new GenericHandle(phandle, handle, (int)ResourceManagerAccess.QueryInformation); var tmRmProps = new TmRmProperties(ResourceManagerHandle.FromHandle(dupHandle)); control.Controls.Add(tmRmProps); } break; case "tmtm": { dupHandle = new GenericHandle(phandle, handle, (int)TmAccess.QueryInformation); var tmTmProps = new TmTmProperties(TmHandle.FromHandle(dupHandle)); control.Controls.Add(tmTmProps); } break; } }; if (dupHandle == null) { // Try to get a handle, since we need one for security editing. try { dupHandle = new GenericHandle(phandle, handle, 0); } catch { } } window.ObjectHandle = dupHandle; window.ShowDialog(); if (dupHandle != null) { dupHandle.Dispose(); } } catch (Exception ex) { PhUtils.ShowException("Unable to show handle properties", ex); } }
public void addOnComplete(TimerHandle onComplete) { this.onComplete = onComplete; }
/// <summary> /// Recycles a previously returned timer handle in order to lower GC pressure (by pooling done internally). /// </summary> public void ReturnTimerHandle(TimerHandle handle) { this.handlesPool.Return(handle); }
public void addOnTimer(TimerHandle onTimer) { this.onTimer = onTimer; }
public WaitForTimeSpan(TimerManager timerManager, TimeSpan timeSpan) { timer = timerManager.StartTimerAfter(timeSpan, Success); }
public void ClearInterval(TimerHandle handle) { UnregisterHandle(handle); }
public void ClearImmediate(TimerHandle handle) { UnregisterHandle(handle); }
private bool UnregisterHandle(TimerHandle handle) { if (handle == null) return false; return RegisteredTimers.Remove(handle); }