using System; namespace ScreenConnect; public abstract class ThreadRunnerBase { public event EventHandler Starting; public event EventHandler Started; public event EventHandler Stopped; public event EventHandler UnexpectedExceptionOccurred; public abstract void EnsureRunState(bool running, bool waitForState = true); protected virtual void OnStarting() { this.RaiseEvent(Starting, EventArgs.Empty); } protected virtual void OnStarted() { this.RaiseEvent(Started, EventArgs.Empty); } protected virtual void OnStopped(bool wasUnexpected) { this.RaiseEvent(Stopped, new ThreadRunnerStoppedEventArgs { WasUnexpected = wasUnexpected }); } protected virtual void OnUnexpectedExceptionOccurred(Exception ex) { this.RaiseEvent(UnexpectedExceptionOccurred, new UnexpectedExceptionOccurredEventArgs { Exception = ex }); } }