• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Threading.WorkItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Threading.WorkItem的典型用法代码示例。如果您正苦于以下问题:C# WorkItem类的具体用法?C# WorkItem怎么用?C# WorkItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WorkItem类属于System.Threading命名空间,在下文中一共展示了WorkItem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Enqueue

                    public void Enqueue(WorkItem item)
                    {
                        Contract.ThrowIfFalse(item.DocumentId != null, "can only enqueue a document work item");

                        this.UpdateLastAccessTime();

                        var added = _workItemQueue.AddOrReplace(item);

                        Logger.Log(FunctionId.WorkCoordinator_DocumentWorker_Enqueue, s_enqueueLogger, Environment.TickCount, item.DocumentId, !added);

                        CheckHigherPriorityDocument(item);

                        SolutionCrawlerLogger.LogWorkItemEnqueue(
                            this.Processor._logAggregator, item.Language, item.DocumentId, item.InvocationReasons, item.IsLowPriority, item.ActiveMember, added);
                    }
开发者ID:GloryChou,项目名称:roslyn,代码行数:15,代码来源:WorkCoordinator.NormalPriorityProcessor.cs


示例17: LiveUpgradeService

        public LiveUpgradeService([ServiceDependency]WorkItem workItem, [ServiceDependency]IPropertyService propertyService)
        {
            this.workItem = workItem;
            this.propertyService = propertyService;

            LiveUpgradeConfigurationSection cs = ConfigurationManager.GetSection(LIVEUPGRADE_SECTION) as LiveUpgradeConfigurationSection;
            UpgradeSetting setting = GetSetting();
            if (cs != null && setting != null)
            {
                detecter = new UpgradeDetecter(this);
                if (setting.CheckInterval > 0) {
                    detecter.CheckInterval = setting.CheckInterval;
                    detecter.Start();
                }
            }
        }
开发者ID:wuyingyou,项目名称:uniframework,代码行数:16,代码来源:LiveUpgradeService.cs


示例18: QueueUserWorkItem

		public static bool QueueUserWorkItem(WaitCallback callback, object state)
		{
			if (callback == null)
			{
				throw new ArgumentNullException("callback");
			}

			WorkItem workItem = new WorkItem()
			{
				Callback = callback,
				State = state,
				Context = ExecutionContext.Capture()
			};

			bool success = false;

			// Start tracking this work item
			lock (_WorkItems)
			{
				_WorkItems.Add(workItem);
			}

			try
			{
				// Place work item on the thread pool queue
				success = ThreadPool.QueueUserWorkItem(new WaitCallback(HandleCallback), workItem);
			}
			catch
			{
				// Work item could not be queued
				success = false;
				throw;
			}
			finally
			{
				if (!success)
				{
					// Stop tracking this work item
					RemoveWorkItem(workItem);
				}
			}

			return success;
		}
开发者ID:Philo,项目名称:Revalee,代码行数:44,代码来源:AbortableThreadPool.cs


示例19: AddPrioritised

        /// <summary>
        /// Adds items to the work queue.
        /// 
        /// If the unique for the item already exists, then the work item is discarded.
        /// 
        /// If the priority is greater than previous items in the queue, then the new work item is
        /// inserted prior to the other items.
        /// 
        /// This code maintains the sorted order of the workitems.
        /// </summary>
        /// <param name="oNewItem"></param>
        public void AddPrioritised(WorkItem oNewItem)
        {
            lock(m_Lock_WorkItem_AddRemove)
            {
                foreach (WorkItem oItem in m_WorkItems)
                    if (oItem.Key.ToString() == oNewItem.Key.ToString())
                    {
                        Debug.WriteLine("PrioritisedArrayList: Key Already Queued: Skipped Request");
                        return;
                    }

                m_MREs.Add(oNewItem.MRE);

                int i = m_WorkItems.BinarySearch(oNewItem);

                if (i < 0)
                    m_WorkItems.Insert(~i, oNewItem);
                else
                    m_WorkItems.Insert(i, oNewItem);
            }
        }
开发者ID:eulalie367,项目名称:littleapps,代码行数:32,代码来源:WorkItemQueue.cs


示例20: Enqueue

                    public void Enqueue(WorkItem item)
                    {
                        Contract.ThrowIfFalse(item.DocumentId != null, "can only enqueue a document work item");

                        // we only put workitem in high priority queue if there is a text change.
                        // this is to prevent things like opening a file, changing in other files keep enqueuing
                        // expensive high priority work.
                        if (!item.InvocationReasons.Contains(PredefinedInvocationReasons.SyntaxChanged))
                        {
                            return;
                        }

                        // check whether given item is for active document, otherwise, nothing to do here
                        if (_processor._documentTracker == null ||
                            _processor._documentTracker.GetActiveDocument() != item.DocumentId)
                        {
                            return;
                        }

                        // we need to clone due to waiter
                        EnqueueActiveFileItem(item.With(Listener.BeginAsyncOperation("ActiveFile")));
                    }
开发者ID:jkotas,项目名称:roslyn,代码行数:22,代码来源:WorkCoordinator.HighPriorityProcessor.cs



注:本文中的System.Threading.WorkItem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tasks.ParallelOptions类代码示例发布时间:2022-05-26
下一篇:
C# Threading.WaitHandle类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap