コード例 #1
0
 public AsyncContext()
 {
     _queue = new TaskQueue();
     _synchronizationContext = new AsyncContextSynchronizationContext(this);
     _taskScheduler = new AsyncContextTaskScheduler(this);
     _taskFactory = new TaskFactory(CancellationToken.None, TaskCreationOptions.HideScheduler, TaskContinuationOptions.HideScheduler, _taskScheduler);
 }
コード例 #2
0
ファイル: AsyncContext.cs プロジェクト: szp11/AsyncEx
 public AsyncContext()
 {
     _queue = new TaskQueue();
     _synchronizationContext = new AsyncContextSynchronizationContext(this);
     _taskScheduler          = new AsyncContextTaskScheduler(this);
     _taskFactory            = new TaskFactory(_taskScheduler);
 }
コード例 #3
0
            /// <summary>
            /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. It is considered equal if it refers to the same underlying async context as this instance.
            /// </summary>
            /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
            /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.</returns>
            public override bool Equals(object obj)
            {
                AsyncContextSynchronizationContext other = obj as AsyncContextSynchronizationContext;

                if (other == null)
                {
                    return(false);
                }
                return(Context == other.Context);
            }
コード例 #4
0
 /// <summary>
 /// Creates some dedicated threads to run submitted tasks with.
 /// </summary>
 /// <param name="threadCount">The number of dedicated threads to create.</param>
 /// <param name="borrowsCallerThread">The thread which is submitted is borrowed to execute other tasks until the submitted work is done.</param>
 /// <param name="startOnCallerThread">Will start running the submitted work on the thread which submitted it.</param>
 /// <param name="threadName">The name of the dedicated threads, can be used for debug/identification purposes.</param>
 public AsyncContext(
     int threadCount = 4,
     bool borrowsCallerThread = true,
     string threadName = "AsyncContextThread")
 {
     this._borrowsCallerThread = borrowsCallerThread;
     workSignal = threadCount == 0 ? null : new SemaphoreSlim(0);
     synchronizationContext = new AsyncContextSynchronizationContext(workSignal, workItems);
     threads = new Thread[threadCount];
     for (int i = 0; i < threadCount; i++)
     {
         var thread = threads[i] = new Thread(ThreadMethod);
         thread.Name = threadName;
         thread.Start();
     }
 }