Inheritance: IPreallocatedWorkItem
Example #1
0
        public NetThread(string name, int sleepTime, Action callback)
        {
            _callback = callback;
            SleepTime = sleepTime;
            _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();
		}