Exemple #1
0
        /// <summary>
        /// generate events asyncronously with random delay
        /// </summary>
        public void Working()
        {
            int n = rnd.Next(5, 10);      //adding more randomness

            StartWork?.Invoke(textBox);
            Thread.Sleep(rnd.Next(30 - n, 40 + n) * 100);

            int m = rnd.Next(20, 50);

            while (!IsClicked)
            {
                switch (rnd.Next(1, 5))
                {
                case 1: { FirstEvent?.Invoke(textBox); break; }

                case 2: { SecondEvent?.Invoke(textBox); break; }

                case 3: { ThirdEvent?.Invoke(textBox); break; }

                case 4: { FourthEvent?.Invoke(textBox); break; }

                default: break;
                }
                Thread.Sleep(rnd.Next(100 - n, 100 + m) * 100);
            }
            //StopWork?.Invoke(textBox);
            StopCalled = true;
        }
Exemple #2
0
        public async Task StartNoUIWork(string title, int totalCount, Func <IAsyncActionWithProgress <uint> > actionFactory)
        {
            StartWork?.Invoke(title, (uint)totalCount);

            var progressHandler = new Progress <uint>((x) => ProgressWork?.Invoke(x));

            using (var cancelSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)))
            {
                await actionFactory().AsTask(cancelSource.Token, progressHandler);

                await Task.Delay(500);

                if (cancelSource.IsCancellationRequested)
                {
                    CancelWork?.Invoke();
                }
                else
                {
                    CompleteWork?.Invoke();
                }
            }
        }
Exemple #3
0
        public async Task StartNoUIWork(string title, Func <IAsyncAction> actionFactory)
        {
            StartWork?.Invoke(title, 1);

            using (var cancelSource = new CancellationTokenSource(TimeSpan.FromSeconds(30)))
            {
                await actionFactory().AsTask(cancelSource.Token);

                ProgressWork?.Invoke(1);

                await Task.Delay(1000);

                if (cancelSource.IsCancellationRequested)
                {
                    CancelWork?.Invoke();
                }
                else
                {
                    CompleteWork?.Invoke();
                }
            }
        }
Exemple #4
0
 internal static void Start(int fileCount)
 {
     FileCount = fileCount;
     StartWork?.Invoke(null, EventArgs.Empty);
     ChangeState?.Invoke(null, EventArgs.Empty);
 }