public void LongRunningTaskAsync(int input)
 {
     Task.Run(() =>
     {
         var result = LongRunningTask(input);
         LongRunningTaskCompleted.Invoke(this, new LongRunningTaskCompletedEventArgs(result));
     });
 }
        public void LongRunningTaskAsync(int input)
        {
            Task.Run(() =>
            {
                isLongRunningTaskStopped = false;
                int result = input;
                // After cancel, the current operation will be finished before returning
                for (int i = 0; i < input && !isLongRunningTaskStopped; i++)
                {
                    result *= input;
                    Thread.Sleep(1000);
                }

                LongRunningTaskCompleted.Invoke(this, new LongRunningTaskCompletedEventArgs(result, null, isLongRunningTaskStopped, null));
            });
        }
        public void LongRunningTaskAsync(int input)
        {
            Task.Run(() =>
            {
                // Signal progress changes to the clients
                int result = input;
                for (int i = 0; i < input; i++)
                {
                    result *= input;
                    Thread.Sleep(1000);

                    // Calculate progress and fire progress changed event
                    int curProgress       = (int)Math.Round((float)(i + 1) / input * 100, 0);
                    var progressEventArgs = new PartialResultProgressChangedEventArgs(result, curProgress, null);
                    LongRunningTaskProgressChanged.Invoke(this, progressEventArgs);
                }

                LongRunningTaskCompleted.Invoke(this, new LongRunningTaskCompletedEventArgs(result));
            });
        }
Beispiel #4
0
        public void LongRunningTaskAsync(int input)
        {
            Task.Run(() =>
            {
                int result  = -1;
                Exception e = null;

                try
                {
                    result = LongRunningTask(input);
                }
                catch (Exception ex)
                {
                    e = ex;
                }
                finally
                {
                    LongRunningTaskCompleted.Invoke(this, new LongRunningTaskCompletedEventArgs(result, e, false, null));
                }
            });
        }