public void StartLongRunningPRocess(Action <ManualResetEvent, Action <string> > action) { LongRunningProcessData threadData = new LongRunningProcessData() { Event = this.Cancel, Work = action, OnStatusUpdate = this.StatusUpdate }; this.Show(); System.Threading.ThreadPool.QueueUserWorkItem(this.ThreadRoutine, threadData); }
private void ThreadRoutine(object obj) { if (obj is LongRunningProcessData) { LongRunningProcessData data = obj as LongRunningProcessData; data.OnStatusUpdate?.Invoke("Starting job"); data.Work(data.Event, data.OnStatusUpdate); data.OnStatusUpdate?.Invoke("Completing job"); this.JobCompleted?.Invoke(); } this.SafeClose(); }