///<summary>Starts the thread which will populate the graph's data. DB context should be set before calling this method.</summary> /// <param name="forceCacheRefesh">Will pass this flag along to the thread which retrieves the cache. If true then cache will be invalidated and re-initialiazed from the db. Use sparingly.</param> /// <param name="onException">Exception handler if something fails. If not set then all exceptions will be swallowed.</param> /// <param name="onThreadDone">Done event handler. Will be invoked when init thread has completed.</param> private void Init(bool forceCacheRefesh = false, ODThread.ExceptionDelegate onException = null, EventHandler onThreadDone = null) { if (_thread != null) { return; } if (onThreadDone == null) { onThreadDone = new EventHandler(delegate(object o, EventArgs e) { }); } if (onException == null) { onException = new ODThread.ExceptionDelegate((Exception e) => { }); } _thread = new ODThread(new ODThread.WorkerDelegate((ODThread x) => { //The thread may have run and return before the window is even ready to display. if (this.IsHandleCreated) { OnThreadStartLocal(this, new EventArgs()); } else { this.HandleCreated += OnThreadStartLocal; } //Alert caller that it's time to start querying the db. OnInit(forceCacheRefesh); })); _thread.Name = "GraphQuantityFilterOverTime.Init"; _thread.AddExceptionHandler(onException); _thread.AddExitHandler(new ODThread.WorkerDelegate((ODThread x) => { try { _thread = null; //The thread may have run and return before the window is even ready to display. if (this.IsHandleCreated) { OnThreadExitLocal(this, new EventArgs()); } else { this.HandleCreated += OnThreadExitLocal; } //Alert caller that db querying is done. onThreadDone(this, new EventArgs()); } catch (Exception) { } })); _thread.Start(true); }
///<summary>Runs the workerDelegate on a separate thread and displays a progress window while the thread is running.</summary> public static void ShowProgressForThread(ODThread.WorkerDelegate workerDelegate, Control parent, string startingMessage = "Please Wait...", ProgBarStyle progStyle = ProgBarStyle.Blocks, string threadName = "ODProgressThread", ODThread.ExceptionDelegate exceptionHandler = null) { ODProgress prog = new ODProgress(Lan.g(parent, startingMessage), progStyle); ODThread thread = new ODThread(workerDelegate); if (exceptionHandler != null) { thread.AddExceptionHandler(exceptionHandler); } thread.Name = threadName; thread.ProgressLog = prog; thread.Start(true); prog.ShowDialog(parent); }