当前位置: 首页>>代码示例>>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;未经允许,请勿转载。