public static LongOperationResult StartOperation(Action <IWorker> doWork, string name, int steps, bool modal = true) { var statusWindow = new LongOperationDlg(steps); statusWindow.OperationName = name; Thread thread = new Thread(() => { doWork(statusWindow); statusWindow.finished = true; }); thread.Name = name; statusWindow.buttonCancel.Clicked += (sender, args) => { statusWindow.isCancelled = true; statusWindow.Visible = false; }; statusWindow.Modal = modal; statusWindow.Show(); thread.Start(); while (!statusWindow.finished) { Gtk.Main.Iteration(); } if (thread.IsAlive) { thread.Interrupt(); } statusWindow.Destroy(); if (statusWindow.IsCancelled) { return(LongOperationResult.Canceled); } return(LongOperationResult.Finished); }
public static LongOperationResult StartOperation(Action<IWorker> doWork, string name, int steps, bool modal=true) { var statusWindow = new LongOperationDlg(steps); statusWindow.OperationName = name; Thread thread = new Thread(()=>{ doWork(statusWindow); statusWindow.finished=true; }); thread.Name = name; statusWindow.buttonCancel.Clicked += (sender,args) => { statusWindow.isCancelled=true; statusWindow.Visible=false; }; statusWindow.Modal = modal; statusWindow.Show(); thread.Start (); while (!statusWindow.finished) { Gtk.Main.Iteration (); } if (thread.IsAlive) thread.Interrupt(); statusWindow.Destroy(); if (statusWindow.IsCancelled) return LongOperationResult.Canceled; return LongOperationResult.Finished; }