public static void Execute(string title, Action <Action <long>, Action <long> > action, UiProgressUnits units = UiProgressUnits.Items) { using (UiProgressWindow window = new UiProgressWindow(title, units)) { Task.Run(() => ExecuteAction(window, action)); window.ShowDialog(); } }
public static T Execute <T>(string title, Func <Action <long>, Action <long>, T> action, UiProgressUnits units = UiProgressUnits.Items) { using (UiProgressWindow window = new UiProgressWindow(title, units)) { Task <T> task = Task.Run(() => ExecuteFunction(window, action)); window.ShowDialog(); return(task.Result); } }
public static void Execute(string title, IProgressSender progressSender, Action action, UiProgressUnits units = UiProgressUnits.Items) { using (UiProgressWindow window = new UiProgressWindow(title, units)) { progressSender.ProgressTotalChanged += window.SetTotal; progressSender.ProgressIncremented += window.Incremented; Task.Run(() => ExecuteAction(window, action)); window.ShowDialog(); } }
private static T ExecuteFunction <T>(UiProgressWindow window, Func <Action <long>, Action <long>, T> action) { try { return(action(window.SetTotal, window.Incremented)); } finally { window.Dispatcher.Invoke(window.Close); } }
private static T ExecuteFunction <T>(UiProgressWindow window, Func <T> func) { try { return(func()); } finally { window.Dispatcher.Invoke(window.Close); } }
private static void ExecuteAction(UiProgressWindow window, Action <Action <long>, Action <long> > action) { try { action(window.SetTotal, window.Incremented); } finally { window.Dispatcher.Invoke(window.Close); } }
private static void ExecuteAction(UiProgressWindow window, Action action) { try { action(); } finally { window.Dispatcher.Invoke(window.Close); } }
public static T Execute <T>(string title, IProgressSender progressSender, Func <T> func, UiProgressUnits units = UiProgressUnits.Items) { using (UiProgressWindow window = new UiProgressWindow(title, units)) { progressSender.ProgressTotalChanged += window.SetTotal; progressSender.ProgressIncremented += window.Incremented; Task <T> task = Task.Run(() => ExecuteFunction(window, func)); window.ShowDialog(); return(task.Result); } }