本文整理汇总了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());
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例5: CheckHigherPriorityDocument
private void CheckHigherPriorityDocument(WorkItem item)
{
if (!item.InvocationReasons.Contains(PredefinedInvocationReasons.HighPriority))
{
return;
}
AddHigherPriorityDocument(item.DocumentId);
}
示例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;
}
示例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);
}
示例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>());
}
示例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); // 获取当前用户的所有授权信息
}
}
}
示例10: AuthenticationService
public AuthenticationService([ServiceDependency]WorkItem workItem, [ServiceDependency] IUserSelectorService userSelector)
{
_userSelector = userSelector;
if (workItem.RootWorkItem == null)
{
_rootWorkItem = workItem;
}
else
{
_rootWorkItem = workItem.RootWorkItem;
}
}
示例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);
}
}
}
示例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);
}
示例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();
}
示例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();
}
}
示例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();
}
}