當前位置: 首頁>>代碼示例>>C#>>正文


C# Threading.WorkItem類代碼示例

本文整理匯總了C#中System.Threading.WorkItem的典型用法代碼示例。如果您正苦於以下問題:C# WorkItem類的具體用法?C# WorkItem怎麽用?C# WorkItem使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WorkItem類屬於System.Threading命名空間,在下文中一共展示了WorkItem類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddWork

        // 1. Work item is added
        public void AddWork(WorkItem workItem)
        {
            // 2. Work task is decomposed
            List<Goal> newGoals = _decompService.Decompose(workItem);

            // 3. The goal's satisfied event is registered with this work enactor
            GoalSatisfiedHandler handler = null;
            handler = delegate(Goal g)
                {
                    GoalSatisified(g, workItem);
                    g.GoalSatisfied -= handler;
                };
            newGoals.ForEach(g => g.GoalSatisfied += handler);

            // 4. The goals are added to this enactor's list against the workitem
            //    and also the list of workitems being processed
            _workitemGoals.Add(workItem, newGoals);
            StartWork(workItem);

            // 5. Goals are registered with the world state service
            newGoals.ForEach(_goalService.RegisterGoal);

            // 6. Notify user of goals etc...
            foreach (var goal in newGoals)
            {
                _user.NotifyUser(workItem.taskName + " - " + goal.ToString());
            }
        }
開發者ID:johnfelipe,項目名稱:inn690,代碼行數:29,代碼來源:HumanWorkProvider.cs

示例2: Cancel

 public WorkItemStatus Cancel(WorkItem item, bool allowAbort)
 {
     if (item == null)
         throw new ArgumentNullException("item");
     lock (_callbacks)
     {
         LinkedListNode<WorkItem> node = _callbacks.Find(item);
         if (node != null)
         {
             _callbacks.Remove(node);
             return WorkItemStatus.Queued;
         }
         else if (_threads.ContainsKey(item))
         {
             if (allowAbort)
             {
                 _threads[item].Abort();
                 _threads.Remove(item);
                 return WorkItemStatus.Aborted;
             }
             else
                 return WorkItemStatus.Executing;
         }
         else
             return WorkItemStatus.Completed;
     }
 }
開發者ID:Ejik,項目名稱:Acotwin,代碼行數:27,代碼來源:AbortableThreadPool.cs

示例3: Load

        /// <summary>
        /// See <see cref="IModuleLoaderService.Load(WorkItem, IModuleInfo[])"/> for more information.
        /// </summary>
        public void Load(WorkItem workItem, params IModuleInfo[] modules)
        {
            Guard.ArgumentNotNull(workItem, "workItem");
            Guard.ArgumentNotNull(modules, "modules");

            InnerLoad(workItem, modules);
        }
開發者ID:Letractively,項目名稱:henoch,代碼行數:10,代碼來源:DependentModuleLoaderService.cs

示例4: EnqueueActiveFileItem

                    private void EnqueueActiveFileItem(WorkItem item)
                    {
                        this.UpdateLastAccessTime();
                        var added = _workItemQueue.AddOrReplace(item);

                        Logger.Log(FunctionId.WorkCoordinator_ActiveFileEnqueue, s_enqueueLogger, Environment.TickCount, item.DocumentId, !added);
                        SolutionCrawlerLogger.LogActiveFileEnqueue(_processor._logAggregator);
                    }
開發者ID:Rickinio,項目名稱:roslyn,代碼行數:8,代碼來源:WorkCoordinator.HighPriorityProcessor.cs

示例5: CheckHigherPriorityDocument

                    private void CheckHigherPriorityDocument(WorkItem item)
                    {
                        if (!item.InvocationReasons.Contains(PredefinedInvocationReasons.HighPriority))
                        {
                            return;
                        }

                        AddHigherPriorityDocument(item.DocumentId);
                    }
開發者ID:GuilhermeSa,項目名稱:roslyn,代碼行數:9,代碼來源:WorkCoordinator.NormalPriorityProcessor.cs

示例6: QueueUserWorkItem

 public static bool QueueUserWorkItem(WaitCallback callback,
                                         object state)
 {
     Contract.Requires(callback != null);
     Contract.Requires(threads != null);
     var item = new WorkItem(callback, state);
     workItemQueue.Enqueue(item);
     return true;
 }
開發者ID:jchidley,項目名稱:GSIOT-NP2,代碼行數:9,代碼來源:System.Threading.cs

示例7: CompleteWork

 public void CompleteWork(WorkItem workItem)
 {
     if (/*_workAgent.started.Contains(workItem) &&*/ WorkAgent.processing.Contains(workItem))
     {
         _user.NotifyUser("Just completed workitem: " + workItem.taskName);
         WorkAgent.Complete(workItem, _workflow);
     }
     _completedGoals.Add(workItem, _workitemGoals[workItem]);
     _workitemGoals.Remove(workItem);
 }
開發者ID:johnfelipe,項目名稱:inn690,代碼行數:10,代碼來源:HumanWorkProvider.cs

示例8: IOTaskScheduler

 /// <summary>Initializes a new instance of the IOTaskScheduler class.</summary>
 public unsafe IOTaskScheduler()
 {
     // Configure the object pool of work items
     _availableWorkItems = new ObjectPool<WorkItem>(() =>
     {
         var wi = new WorkItem { _scheduler = this };
         wi._pNOlap = new Overlapped().UnsafePack(wi.Callback, null);
         return wi;
     }, new ConcurrentStack<WorkItem>());
 }
開發者ID:bevacqua,項目名稱:Swarm,代碼行數:11,代碼來源:IOTaskScheduler.cs

示例9: AuthorizationService

 /// <summary>
 /// Initializes a new instance of the <see cref="AuthorizationService"/> class.
 /// </summary>
 /// <param name="workItem">The work item.</param>
 public AuthorizationService([ServiceDependency]WorkItem workItem)
 {
     lock (syncObj) {
         this.workItem = workItem;
         authorizationStoreService = workItem.Services.Get<IAuthorizationStoreService>();
         if (authorizationStoreService != null) {
             authorizations = authorizationStoreService.GetAuthorizationsByUser(Thread.CurrentPrincipal.Identity.Name); // 獲取當前用戶的所有授權信息
         }
     }
 }
開發者ID:wuyingyou,項目名稱:uniframework,代碼行數:14,代碼來源:AuthorizationService.cs

示例10: AuthenticationService

 public AuthenticationService([ServiceDependency]WorkItem workItem, [ServiceDependency] IUserSelectorService userSelector)
 {
     _userSelector = userSelector;
     if (workItem.RootWorkItem == null)
     {
         _rootWorkItem = workItem;
     }
     else
     {
         _rootWorkItem = workItem.RootWorkItem;
     }
 }
開發者ID:rentianhua,項目名稱:AgileMVC,代碼行數:12,代碼來源:AuthenticationService.cs

示例11: QueueUserWorkItem

        public void QueueUserWorkItem(WaitCallback callback, object parameter)
        {
            var workItem = new WorkItem(callback, parameter);

            lock (_jobQueue)
            {
                _jobQueue.Enqueue(workItem);
                if (_threadsWaiting > 0)
                {
                    Monitor.Pulse(_jobQueue);
                }
            }
        }
開發者ID:Sir-Loin,項目名稱:sdrsharp_experimental,代碼行數:13,代碼來源:SharpThreadPool.cs

示例12: Enqueue

                    public void Enqueue(WorkItem item)
                    {
                        this.UpdateLastAccessTime();

                        // Project work
                        item = item.With(documentId: null, projectId: item.ProjectId, asyncToken: this.Processor._listener.BeginAsyncOperation("WorkItem"));

                        var added = _workItemQueue.AddOrReplace(item);

                        Logger.Log(FunctionId.WorkCoordinator_Project_Enqueue, s_enqueueLogger, Environment.TickCount, item.ProjectId, !added);

                        SolutionCrawlerLogger.LogWorkItemEnqueue(this.Processor._logAggregator, item.ProjectId);
                    }
開發者ID:elemk0vv,項目名稱:roslyn-1,代碼行數:13,代碼來源:WorkCoordinator.LowPriorityProcessor.cs

示例13: TimedWorker

        public TimedWorker()
        {
            work = new WorkItem();
            workIsWaiting = new AutoResetEvent(false);
            workerIsStarting = new AutoResetEvent(false);
            workerIsDone = new AutoResetEvent(false);
            workIsDone = new AutoResetEvent(false);

            manager = new Thread(new ThreadStart(RunManager));
            worker = new Thread(new ThreadStart(RunWorker));
            manager.Start();
            worker.Start();
        }
開發者ID:juhan,項目名稱:NModel,代碼行數:13,代碼來源:TimedWorker.cs

示例14: Send

 public override void Send(SendOrPostCallback d, object state)
 {
     if (Thread.CurrentThread == _uiThread)
     {
         d(state);
     }
     else
     {
         var workItem = new WorkItem { Callback = d, State = state, Handle = new AutoResetEvent(false) };
         _workItems.Add(workItem);
         workItem.Handle.WaitOne();
     }
 }
開發者ID:yufeih,項目名稱:Nine.Common,代碼行數:13,代碼來源:UITestSynchronizationContext.cs

示例15: Send

 public override void Send(SendOrPostCallback d, object state)
 {
     if (Thread.CurrentThread == uiThread)
     {
         d(state);
     }
     else
     {
         EnsureUIThread();
         var workItem = new WorkItem { callback = d, state = state, handle = new AutoResetEvent(false) };
         workItems.Add(workItem);
         workItem.handle.WaitOne();
     }
 }
開發者ID:freemsly,項目名稱:Nine.Storage,代碼行數:14,代碼來源:UISynchronizationContext.cs


注:本文中的System.Threading.WorkItem類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。