本文整理汇总了C#中WorkerThread类的典型用法代码示例。如果您正苦于以下问题:C# WorkerThread类的具体用法?C# WorkerThread怎么用?C# WorkerThread使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WorkerThread类属于命名空间,在下文中一共展示了WorkerThread类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public void Test()
{
var th = new WorkerThread();
//
#if false
{
var a = th.StartNew(Worker0);
while (!a.Wait(0)) {
Thread.Sleep(1);
}
Assert.AreEqual(1, Worker0Count);
}
{
var a = th.StartNew(Worker1, 0);
while (!a.Wait(0)) {
Thread.Sleep(1);
}
Assert.AreEqual(1, Worker1Count);
}
#endif
{
var a = th.StartNew(Worker2);
while (!a.Wait(0)) {
Thread.Sleep(1);
}
Assert.AreEqual(1, Worker2Count);
}
{
var a = th.StartNew(Worker3, 0);
while (!a.Wait(0)) {
Thread.Sleep(1);
}
Assert.AreEqual(1, Worker3Count);
}
}
示例2: Should_not_call_processor_when_queue_is_empty
public void Should_not_call_processor_when_queue_is_empty()
{
var worker = new TestProcessor();
var target = new WorkerThread<int>("test", TimeSpan.FromMilliseconds(10), worker.Process);
worker.Go.WaitOne(TimeSpan.FromSeconds(1)).Should().Be.False();
}
示例3: DoWorkShouldNotCallWorkItemDequeueWhenWorkerThreadManagerShouldExitWorkerThreadReturnsTrue
public void DoWorkShouldNotCallWorkItemDequeueWhenWorkerThreadManagerShouldExitWorkerThreadReturnsTrue()
{
WorkerThreadManagerStub workerThreadManager = WorkerThreadManagerStub.Create();
ManualResetEvent manualResetEvent = new ManualResetEvent(false);
IWorkItemQueue workItemQueue = Substitute.For<IWorkItemQueue>();
WorkerThread workerThread = new WorkerThread(workerThreadManager, workItemQueue, "Test", false);
workerThreadManager.WorkerThreadExiting += (sender, args) =>
{
if (args.WorkerThreadExitReason == WorkerThreadExitReason.MaximumThreadCountExceeded)
{
manualResetEvent.Set();
}
};
workerThreadManager.ShouldExitWorkerThread(workerThread, false).ReturnsForAnyArgs(true);
workerThread.Start();
manualResetEvent.WaitOne(500);
workerThread.Stop();
Wait.While(() => workerThread.Thread.IsAlive, 300);
Assert.AreEqual(false, workerThread.Thread.IsAlive);
workItemQueue.DidNotReceive().Dequeue();
}
示例4: SynchronizationContextMock
public SynchronizationContextMock()
{
CallQueued = new Semaphore(0, Int32.MaxValue);
m_WorkItemQueue = new Queue<WorkItem>();
m_WorkerThread = new WorkerThread("SynchronizationContextMockThread", this);
}
示例5: CustomThreadPool
public CustomThreadPool(int NumberOfThreads)
{
WorkerThreads = new WorkerThread[NumberOfThreads];
for (int n = 0; n < NumberOfThreads; n++)
{
WorkerThreads[n] = new WorkerThread();
}
}
示例6: WorkerThreadPoolStartingNewWorkerThreadEventArgs
/// <summary>
/// İşçi Thread havuzu yeni bir işçi Thread'i başlatıyor olay argümanları sınıfı inşacı metodu.
/// </summary>
/// <param name="currentNumberOfWorkerThreads">Mevcut işçi thread sayısı.</param>
/// <param name="workerThread">İşçi Thread.</param>
public WorkerThreadPoolStartingNewWorkerThreadEventArgs(int currentNumberOfWorkerThreads, WorkerThread workerThread)
{
if (workerThread == null)
{
throw new ArgumentNullException("workerThread");
}
m_CurrentNumberOfWorkerThreads = currentNumberOfWorkerThreads;
m_WorkerThread = workerThread;
}
开发者ID:QuickOrBeDead,项目名称:Labo.Threading,代码行数:15,代码来源:WorkerThreadPoolStartingNewWorkerThreadEventArgs.cs
示例7: Scheduler
/// <summary>
/// Constructs a new scheduler
/// </summary>
/// <param name="connection">The database connection</param>
/// <param name="worker">The worker thread</param>
/// <param name="datalock">The database lock object</param>
public Scheduler(WorkerThread<Server.Runner.IRunnerData> worker)
{
m_thread = new Thread(new ThreadStart(Runner));
m_worker = worker;
m_worker.CompletedWork += OnCompleted;
m_schedule = new ISchedule[0];
m_terminate = false;
m_event = new AutoResetEvent(false);
m_updateTasks = new Dictionary<Server.Runner.IRunnerData, Tuple<ISchedule, DateTime, DateTime>>();
m_thread.IsBackground = true;
m_thread.Name = "TaskScheduler";
m_thread.Start();
}
示例8: Should_be_able_to_dispose_failing_worker
public void Should_be_able_to_dispose_failing_worker()
{
var worker = new TestProcessor();
var target = new WorkerThread<int>("test", TimeSpan.FromDays(1), worker.Process);
target.Enqueue(1);
target.Dispose();
worker.Logs.Should().Have.SameSequenceAs(new[] {
"1"
});
}
示例9: Should_dequeue_all_when_disposing
public void Should_dequeue_all_when_disposing()
{
var worker = new TestProcessor();
var target = new WorkerThread<int>("test", TimeSpan.FromDays(1), worker.Process);
target.Enqueue(1);
target.Enqueue(2);
target.Enqueue(3);
target.Dispose();
worker.Logs.Should().Have.SameSequenceAs(new[] {
"1, 2, 3"
});
}
示例10: ThreadPoolSynchronizer
public ThreadPoolSynchronizer(uint poolSize,string poolName)
{
if(poolSize == 0)
{
throw new InvalidOperationException("Pool size cannot be zero");
}
CallQueued = new Semaphore(0,Int32.MaxValue);
m_WorkItemQueue = new Queue<WorkItem>();
m_WorkerThreads = new WorkerThread[poolSize];
for(int index = 0;index<poolSize;index++)
{
m_WorkerThreads[index] = new WorkerThread(poolName + " " + (index+1),this);
}
}
示例11: Add
/// <summary>
/// Add a new callback function to the worker thread.
/// </summary>
public static void Add(CallbackFunction fn, object param)
{
if (mInstance == null)
{
GameObject go = new GameObject("_WorkerThread");
DontDestroyOnLoad(go);
mInstance = go.AddComponent<WorkerThread>();
mInstance.mThread = new Thread(mInstance.ThreadFunction);
mInstance.mThread.Start();
}
Entry ent = new Entry();
ent.fnct = fn;
ent.param = param;
lock (mInstance) mInstance.mActive.Add(ent);
}
示例12: Start
/// <summary>
/// Blocks until all the ReceivingThreads are started.
/// </summary>
public override void Start()
{
Logger.Info("Starting service '" + ServiceName + "'.");
Logger.Info("Configuration: " + this.PrettyFormat());
for (int i = 0; i < NumberOfWorkingThreads; i++)
{
WorkerThread t = new WorkerThread("Receiving thread " + i.ToString("00"), ReceiveOneMessageFromTransport);
t.Stopped += (x, e) =>
{
if (e.Error != null)
{
WorkerThread worker = (WorkerThread)x;
Logger.Error(worker.Id + " threw an exception", e.Error);
}
};
ReceivingThreads.Add(t);
t.Start();
}
}
示例13: CoreDriver
public CoreDriver(UIWindow uiWindow, Configuration config)
{
IsDisposed = false;
try
{
_config = config;
_inputAggregator = new InputAggregator();
_buttonStates = SnesJoypadButtons.None;
_workerThread = new WorkerThread();
_workerThread.DoWork(() =>
{
_uiWindow = uiWindow;
_snes = new Snes();
_snes.VideoUpdated += Snes_VideoUpdated;
_snes.AudioUpdated += Snes_AudioUpdated;
_snes.SetControllerPortDevice(1, SnesDevice.Joypad);
_inputAggregator.InputReceived += InputAggregator_InputReceived;
_isAudioSynced = true;
_isVideoSynced = false;
_isRunning = false;
_stopwatch = new Stopwatch();
_stopwatch.Start();
_frameCount = 0;
});
_workerThread.WaitFor();
}
catch
{
Dispose();
throw;
}
}
示例14: StartShouldStartThread
public void StartShouldStartThread()
{
WorkerThreadManagerStub workerThreadManager = WorkerThreadManagerStub.Create();
IWorkItemQueue workItemQueue = Substitute.For<IWorkItemQueue>();
workItemQueue.Dequeue().Returns((IWorkItem)null);
WorkerThread workerThread = new WorkerThread(workerThreadManager, workItemQueue, "Test", false);
workerThreadManager.ShouldExitWorkerThread(workerThread, false).Returns(false);
workerThread.Start();
Wait.While(() => !workerThread.Thread.IsAlive, 300);
Assert.AreEqual(true, workerThread.Thread.IsAlive);
workerThread.Stop();
Wait.While(() => workerThread.Thread.IsAlive, 300);
Assert.AreEqual(false, workerThread.Thread.IsAlive);
}
示例15: Should_dequeue_in_batch
public void Should_dequeue_in_batch()
{
var worker = new TestProcessor();
var target = new WorkerThread<int>("test", TimeSpan.FromSeconds(.75), worker.Process);
target.Enqueue(1);
target.Enqueue(2);
target.Enqueue(3);
worker.Go.WaitOne();
target.Enqueue(4);
target.Enqueue(5);
target.Enqueue(6);
worker.Go.WaitOne();
worker.Logs.Should().Have.SameSequenceAs(new[] {
"1, 2, 3",
"4, 5, 6"
});
}