protected void StartLongOperation(LongOperation longOperation) { //waitLongOperationCompleted = AsyncOperationManager.CreateOperation(null); longOperation.CancellingTimeoutMilliSeconds = 10000; longOperation.CancellingTimeoutExpired += new EventHandler(LongOperation_CancellingTimeoutExpired); longOperation.Completed += new EventHandler <LongOperationCompletedEventArgs>(LongOperation_Completed); progressControl = CreateProgressControl(); progressControl.ShowProgress(longOperation); longOperation.StartAsync(); OnOperationStarted(); }
static async Task Main(string[] args) { var operation = new LongOperation(() => { Thread.Sleep(2000); return(0); }); operation.Log = s => Console.WriteLine(s); await operation.StartAsync(); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public async Task StartAsync() { var operation = new LongOperation(() => { Thread.Sleep(2000); return(0); }); operation.Log = text => { if (log.InvokeRequired) { log.Invoke((MethodInvoker) delegate { log.Text += text + Environment.NewLine; }); } else { log.Text += text + Environment.NewLine; } }; await operation.StartAsync(); }