Esempio n. 1
0
        public void Start()
        {
            if (_running)
            {
                return;
            }
            _running = true;
#if USE_WINRT
            var thread = new PreallocatedWorkItem(ThreadLogic, WorkItemPriority.Normal, WorkItemOptions.TimeSliced);
            thread.RunAsync().AsTask();
#else
            _thread = new Thread(ThreadLogic)
            {
                Name         = _name,
                IsBackground = true
            };
            _thread.Start();
#endif
        }
        public void ThrowIfCancellationRequested_Error()
        {
            ManualResetEventSlim StartWaiter = new ManualResetEventSlim(false);
            ManualResetEventSlim Waiter      = new ManualResetEventSlim(false);
            PreallocatedWorkItem workitem    = new PreallocatedWorkItem(new WorkItemHandler((target) =>
            {
                Scheduler <WaitingScheduledAction> .AsyncActionSchedulerAction action = new Scheduler <WaitingScheduledAction> .AsyncActionSchedulerAction(target);
                StartWaiter.Wait();

                CustomAssert.ThrowsException <OperationCanceledException>(() =>
                {
                    action.ThrowIfCancellationRequested();
                });
                Waiter.Set();
            }));

            IAsyncAction iaa = workitem.RunAsync();

            iaa.Cancel();
            StartWaiter.Set();
            Waiter.Wait();
        }