public async Task CancelTaskTest()
        {
            int started  = 0;
            int finished = 0;

            using (var task = new SharedTask(RunAsync))
                using (var cancellationTokenSource = new CancellationTokenSource(SmallDelay))
                {
                    var task1 = task.GetOrCreateAsync(cancellationTokenSource.Token);
                    var task2 = task.GetOrCreateAsync();

                    await Task.WhenAll(task1, task2);

                    Assert.That(started, Is.EqualTo(1));
                    Assert.That(finished, Is.EqualTo(1));
                }

            async Task RunAsync(CancellationToken cancellationToken)
            {
                started++;
                await Task.Delay(Delay, cancellationToken);

                finished++;
            }
        }
Exemple #2
0
        public void LoadSharedData()
        {
            Logger.AddTrace("Loading Shared Data");

            this.SharedTasks.Clear();

            try
            {
                ShareManagerServiceClient shareServices = new ShareManagerServiceClient();

                SharedTaskDTO[] sharedTasks = shareServices.GetSharedTasks(Environment.MachineName);

                foreach (SharedTaskDTO task in sharedTasks)
                {
                    ObjectMapper mapper     = new ObjectMapper(typeof(SharedTask), typeof(SharedTaskDTO));
                    SharedTask   sharedTask = mapper.Map(task, true) as SharedTask;

                    this.SharedTasks.Add(sharedTask);
                }

                shareServices.Close();
            }
            catch (Exception e)
            {
                Logger.AddException(e);
            }
        }
        public async Task SingleTaskTest()
        {
            int started  = 0;
            int finished = 0;

            using (var task = new SharedTask(RunAsync))
            {
                var task1 = task.GetOrCreateAsync();
                var task2 = task.GetOrCreateAsync();

                await Task.WhenAll(task1, task2);

                Assert.That(started, Is.EqualTo(1));
                Assert.That(finished, Is.EqualTo(1));
            }

            async Task RunAsync()
            {
                started++;
                await Task.Delay(Delay);

                finished++;
            }
        }
Exemple #4
0
 public void SetUp()
 {
     _started  = 0;
     _finished = 0;
     _task     = new SharedTask <int>(GetNumberAsync);
 }