/// <summary> /// Method OnTimerElapsed /// </summary> /// <param name="obj">An object containing application-specific information relevant to the method invoked by this delegate, or null.</param> private void OnTimerElapsed(object obj) { if (NativeMethodsHelper.GetLastInputTime() >= this.IdleTimeout) { if (this._autoStop) { this.Stop(); } // Copy a reference to the delegate field now into a temporary field for thread safety EventHandler temp = Interlocked.CompareExchange(ref this.IdleOccurred, null, null); if (temp != null) { temp(this, EventArgs.Empty); } } }