/// <summary> /// Construct a new TestWorker. /// </summary> /// <param name="queue">The queue from which to pull work items</param> /// <param name="name">The name of this worker</param> public TestWorker(WorkItemQueue queue, string name) { Guard.ArgumentNotNull(queue, nameof(queue)); WorkQueue = queue; Name = name; }
/// <summary> /// Construct a ParallelWorkItemDispatcher /// </summary> /// <param name="levelOfParallelism">Number of workers to use</param> public ParallelWorkItemDispatcher(int levelOfParallelism) { _levelOfParallelism = levelOfParallelism; // Initialize WorkShifts Shifts = new WorkShift[] { _parallelShift, _nonParallelShift, _nonParallelSTAShift }; foreach (var shift in Shifts) { shift.EndOfShift += OnEndOfShift; } // Set up queues for lazy initialization _parallelQueue = new Lazy <WorkItemQueue>(() => { var parallelQueue = new WorkItemQueue("ParallelQueue"); _parallelShift.AddQueue(parallelQueue); for (int i = 1; i <= _levelOfParallelism; i++) { string name = string.Format("Worker#" + i.ToString()); _parallelShift.Assign(new TestWorker(parallelQueue, name, ApartmentState.MTA)); } return(parallelQueue); }); _parallelSTAQueue = new Lazy <WorkItemQueue>(() => { var parallelSTAQueue = new WorkItemQueue("ParallelSTAQueue"); _parallelShift.AddQueue(parallelSTAQueue); _parallelShift.Assign(new TestWorker(parallelSTAQueue, "Worker#STA", ApartmentState.STA)); return(parallelSTAQueue); }); _nonParallelQueue = new Lazy <WorkItemQueue>(() => { var nonParallelQueue = new WorkItemQueue("NonParallelQueue"); _nonParallelShift.AddQueue(nonParallelQueue); _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#STA_NP", ApartmentState.MTA)); return(nonParallelQueue); }); _nonParallelSTAQueue = new Lazy <WorkItemQueue>(() => { var nonParallelSTAQueue = new WorkItemQueue("NonParallelSTAQueue"); _nonParallelSTAShift.AddQueue(nonParallelSTAQueue); _nonParallelSTAShift.Assign(new TestWorker(nonParallelSTAQueue, "Worker#NP_STA", ApartmentState.STA)); return(nonParallelSTAQueue); }); }
/// <summary> /// Construct a new TestWorker. /// </summary> /// <param name="queue">The queue from which to pull work items</param> /// <param name="name">The name of this worker</param> /// <param name="apartmentState">The apartment state to use for running tests</param> public TestWorker(WorkItemQueue queue, string name, ApartmentState apartmentState) { _readyQueue = queue; _workerThread = new Thread(new ThreadStart(TestWorkerThreadProc)); _workerThread.Name = name; _workerThread.SetApartmentState(apartmentState); }
public void CreateQueue() { #if APARTMENT_STATE _queue = new WorkItemQueue("TestQ", true, ApartmentState.MTA); #else _queue = new WorkItemQueue("TestQ", true); #endif }
public void SetUp() { _queue = new WorkItemQueue("TestQ"); #if NETCF _worker = new TestWorker(_queue, "TestQ_Worker"); #else _worker = new TestWorker(_queue, "TestQ_Worker", ApartmentState.MTA); #endif }
public void SetUp() { #if APARTMENT_STATE _queue = new WorkItemQueue("TestQ", true, ApartmentState.MTA); #else _queue = new WorkItemQueue("TestQ", true); #endif _worker = new TestWorker(_queue, "TestQ_Worker"); }
/// <summary> /// Construct a ParallelWorkItemDispatcher /// </summary> /// <param name="levelOfParallelism">Number of workers to use</param> public ParallelWorkItemDispatcher(int levelOfParallelism) { _levelOfParallelism = levelOfParallelism; Shifts = new WorkShift[] { _parallelShift, _nonParallelShift, _nonParallelSTAShift }; foreach (var shift in Shifts) shift.EndOfShift += OnEndOfShift; _parallelQueue = new Lazy<WorkItemQueue>(() => { var parallelQueue = new WorkItemQueue("ParallelQueue"); _parallelShift.AddQueue(parallelQueue); for (int i = 1; i <= _levelOfParallelism; i++) { string name = string.Format("Worker#" + i.ToString()); _parallelShift.Assign(new TestWorker(parallelQueue, name, ApartmentState.MTA)); } return parallelQueue; }); _parallelSTAQueue = new Lazy<WorkItemQueue>(() => { var parallelSTAQueue = new WorkItemQueue("ParallelSTAQueue"); _parallelShift.AddQueue(parallelSTAQueue); _parallelShift.Assign(new TestWorker(parallelSTAQueue, "Worker#STA", ApartmentState.STA)); return parallelSTAQueue; }); _nonParallelQueue = new Lazy<WorkItemQueue>(() => { var nonParallelQueue = new WorkItemQueue("NonParallelQueue"); _nonParallelShift.AddQueue(nonParallelQueue); _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#STA_NP", ApartmentState.MTA)); return nonParallelQueue; }); _nonParallelSTAQueue = new Lazy<WorkItemQueue>(() => { var nonParallelSTAQueue = new WorkItemQueue("NonParallelSTAQueue"); _nonParallelSTAShift.AddQueue(nonParallelSTAQueue); _nonParallelSTAShift.Assign(new TestWorker(nonParallelSTAQueue, "Worker#NP_STA", ApartmentState.STA)); return nonParallelSTAQueue; }); }
public void HasWorkTest() { var q = new WorkItemQueue("test", true, ApartmentState.MTA); _shift.AddQueue(q); Assert.False(_shift.HasWork, "Should not have work initially"); q.Enqueue(Fakes.GetWorkItem(this, "Test1")); Assert.That(_shift.HasWork, "Should have work after enqueue"); _shift.Start(); Assert.That(_shift.HasWork, "Should have work after starting"); }
/// <summary> /// Add a WorkItemQueue to the shift, starting it if the /// shift is currently active. /// </summary> public void AddQueue(WorkItemQueue queue) { log.Debug("{0} shift adding queue {1}", Name, queue.Name); Queues.Add(queue); if (IsActive) { queue.Start(); } }
/// <summary> /// Construct a new TestWorker. /// </summary> /// <param name="queue">The queue from which to pull work items</param> /// <param name="name">The name of this worker</param> /// <param name="apartmentState">The apartment state to use for running tests</param> public TestWorker(WorkItemQueue queue, string name #if !NETCF , ApartmentState apartmentState #endif ) { _readyQueue = queue; _workerThread = new Thread(new ThreadStart(TestWorkerThreadProc)); _workerThread.Name = name; #if !NETCF _workerThread.SetApartmentState(apartmentState); #endif }
/// <summary> /// Construct a new TestWorker. /// </summary> /// <param name="queue">The queue from which to pull work items</param> /// <param name="name">The name of this worker</param> public TestWorker(WorkItemQueue queue, string name)
public void HasWorkTest() { var q = new WorkItemQueue("test"); _shift.AddQueue(q); Assert.False(_shift.HasWork, "Should not have work initially"); q.Enqueue(Fakes.GetWorkItem(this, "Test1")); Assert.That(_shift.HasWork, "Should have work after enqueue"); _shift.Start(); Assert.That(_shift.HasWork, "Should have work after starting"); }
public void SetUp() { _queue = new WorkItemQueue("TestQ"); _worker = new TestWorker(_queue, "TestQ_Worker", ApartmentState.MTA); }
public SavedState(WorkItemQueue queue) { InnerQueues = queue._innerQueues; AddId = queue._addId; RemoveId = queue._removeId; }
/// <summary> /// Construct a new TestWorker. /// </summary> /// <param name="queue">The queue from which to pull work items</param> /// <param name="name">The name of this worker</param> /// <param name="apartmentState">The apartment state to use for running tests</param> public TestWorker(WorkItemQueue queue, string name, ApartmentState apartmentState) { WorkQueue = queue; Name = name; Apartment = apartmentState; }
public SavedState(WorkItemQueue queue) { InnerQueues = queue._innerQueues; }
public void CreateQueue() { _queue = new WorkItemQueue("TestQ"); }
/// <summary> /// Construct a ParallelWorkItemDispatcher /// </summary> /// <param name="levelOfParallelism">Number of workers to use</param> public ParallelWorkItemDispatcher(int levelOfParallelism) { _levelOfParallelism = levelOfParallelism; Shifts = new WorkShift[] { _parallelShift, _nonParallelShift, #if !NETCF _nonParallelSTAShift #endif }; foreach (var shift in Shifts) { shift.EndOfShift += OnEndOfShift; } _parallelQueue = new Lazy <WorkItemQueue>(() => { var parallelQueue = new WorkItemQueue("ParallelQueue"); _parallelShift.AddQueue(parallelQueue); for (int i = 1; i <= _levelOfParallelism; i++) { string name = string.Format("Worker#" + i.ToString()); #if NETCF _parallelShift.Assign(new TestWorker(parallelQueue, name)); #else _parallelShift.Assign(new TestWorker(parallelQueue, name, ApartmentState.MTA)); #endif } return(parallelQueue); }); #if !NETCF _parallelSTAQueue = new Lazy <WorkItemQueue>(() => { var parallelSTAQueue = new WorkItemQueue("ParallelSTAQueue"); _parallelShift.AddQueue(parallelSTAQueue); _parallelShift.Assign(new TestWorker(parallelSTAQueue, "Worker#STA", ApartmentState.STA)); return(parallelSTAQueue); }); #endif _nonParallelQueue = new Lazy <WorkItemQueue>(() => { var nonParallelQueue = new WorkItemQueue("NonParallelQueue"); _nonParallelShift.AddQueue(nonParallelQueue); #if NETCF _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#NP")); #else _nonParallelShift.Assign(new TestWorker(nonParallelQueue, "Worker#STA_NP", ApartmentState.MTA)); #endif return(nonParallelQueue); }); #if !NETCF _nonParallelSTAQueue = new Lazy <WorkItemQueue>(() => { var nonParallelSTAQueue = new WorkItemQueue("NonParallelSTAQueue"); _nonParallelSTAShift.AddQueue(nonParallelSTAQueue); _nonParallelSTAShift.Assign(new TestWorker(nonParallelSTAQueue, "Worker#NP_STA", ApartmentState.STA)); return(nonParallelSTAQueue); }); #endif }
public void CreateQueue() { _queue = new WorkItemQueue("TestQ", true, ApartmentState.MTA); }
/// <summary> /// Add a WorkItemQueue to the shift, starting it if the /// shift is currently active. /// </summary> public void AddQueue(WorkItemQueue queue) { log.Debug("{0} shift adding queue {1}", _name, queue.Name); Queues.Add(queue); if (this.IsActive) queue.Start(); }