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

C# WorkerThread类代码示例

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

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



WorkerThread类属于命名空间,在下文中一共展示了WorkerThread类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
     }
 }
开发者ID:m5knt,项目名称:BrownSugar,代码行数:35,代码来源:WorkerThreadTest.cs


示例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();
        }
开发者ID:gimmi,项目名称:Log4Rabbit,代码行数:7,代码来源:WorkerThreadTest.cs


示例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();
        }
开发者ID:QuickOrBeDead,项目名称:Labo.Threading,代码行数:27,代码来源:WorkerThreadFixture.cs


示例4: SynchronizationContextMock

        public SynchronizationContextMock()
        {
            CallQueued = new Semaphore(0, Int32.MaxValue);
            m_WorkItemQueue = new Queue<WorkItem>();

            m_WorkerThread = new WorkerThread("SynchronizationContextMockThread", this);
        }
开发者ID:jfromaniello,项目名称:prismcontrib,代码行数:7,代码来源:SynchronizationContextMock.cs


示例5: CustomThreadPool

 public CustomThreadPool(int NumberOfThreads)
 {
     WorkerThreads = new WorkerThread[NumberOfThreads];
     for (int n = 0; n < NumberOfThreads; n++)
     {
         WorkerThreads[n] = new WorkerThread();
     }
 }
开发者ID:ktj007,项目名称:smrr-server,代码行数:8,代码来源:CustomThreadPool.cs


示例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();
 }
开发者ID:thekrugers,项目名称:duplicati,代码行数:19,代码来源:Scheduler.cs


示例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"
            });
        }
开发者ID:gimmi,项目名称:Log4Rabbit,代码行数:13,代码来源:WorkerThreadTest.cs


示例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"
            });
        }
开发者ID:gimmi,项目名称:Log4Rabbit,代码行数:15,代码来源:WorkerThreadTest.cs


示例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);
             }
        }
开发者ID:knunery,项目名称:wcf-perf-test,代码行数:15,代码来源:ThreadPoolSynchronizer.cs


示例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);
    }
开发者ID:Greigy,项目名称:TheGame,代码行数:19,代码来源:WorkerThread.cs


示例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();
     }
 }
开发者ID:rodolfograve,项目名称:Romialyo.NET-SDK,代码行数:22,代码来源:MessagesProcessorServiceBase.cs


示例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;
            }
        }
开发者ID:MiLO83,项目名称:libsnesdotnet,代码行数:41,代码来源:CoreDriver.cs


示例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);
        }
开发者ID:QuickOrBeDead,项目名称:Labo.Threading,代码行数:21,代码来源:WorkerThreadFixture.cs


示例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"
            });
        }
开发者ID:gimmi,项目名称:Log4Rabbit,代码行数:22,代码来源:WorkerThreadTest.cs


示例16: execute

        execute(ThreadPoolWorkItem workItem)
        {
            _m.Lock();
            try
            {
                Debug.Assert(!_destroyed);
                if(_workItems.Count == 0)
                {
                    _m.Notify();
                }
                _workItems.Enqueue(workItem);

                //
                // If this is a dynamic thread pool which can still grow and if all threads are
                // currently busy dispatching or about to dispatch, we spawn a new thread to 
                // execute this new work item right away.
                //
                if(_threads.Count < _sizeMax && 
                   (_inUse + _workItems.Count) > _threads.Count &&
                   !_destroyed)
                {
                    if(_instance.traceLevels().threadPool >= 1)
                    {
                        string s = "growing " + _prefix + ": Size = " + (_threads.Count + 1);
                        _instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s);
                    }
                    
                    try
                    {
                        WorkerThread t = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++);
                        if(_hasPriority)
                        {
                            t.start(_priority);
                        }
                        else
                        {
                            t.start(ThreadPriority.Normal);
                        }
                        _threads.Add(t);
                    }
                    catch(System.Exception ex)
                    {
                        string s = "cannot create thread for `" + _prefix + "':\n" + ex;
                        _instance.initializationData().logger.error(s);
                    }
                }
            }
            finally
            {
                _m.Unlock();
            }
        }
开发者ID:bholl,项目名称:zeroc-ice,代码行数:52,代码来源:ThreadPool.cs


示例17: ClearFromBusyWorkersList

 protected virtual void ClearFromBusyWorkersList(WorkerThread wt) 
 {
     lock(nextRunnableLock) 
     {
         busyWorkers.Remove(wt);
         Monitor.PulseAll(nextRunnableLock);
     }
 }
开发者ID:kisflying,项目名称:kion,代码行数:8,代码来源:SimpleThreadPool.cs


示例18: SetUp

			public Task SetUp (TestSuite suite)
			{
				worker = new WorkerThread ();
				return Task.FromResult<object> (null);
			}
开发者ID:RafasTavares,项目名称:mac-samples,代码行数:5,代码来源:CFNetworkTestAddin.cs


示例19: MakeAvailable

 protected void MakeAvailable(WorkerThread wt)
 {
     lock (nextRunnableLock)
     {
         if (!isShutdown)
         {
             availWorkers.Add(wt);
         }
         busyWorkers.Remove(wt);
         Monitor.PulseAll(nextRunnableLock);
     }
 }
开发者ID:kisflying,项目名称:kion,代码行数:12,代码来源:SimpleThreadPool.cs


示例20: CreateWorkerThreads

        /// <summary>
        /// Creates the worker threads.
        /// </summary>
        /// <param name="threadCount">The thread count.</param>
        /// <returns></returns>
        protected internal virtual IList CreateWorkerThreads(int threadCount)
        {
            workers = new ArrayList();
            for (int i = 1; i <= threadCount; ++i)
            {
                WorkerThread wt = new WorkerThread(
                    this,
                    string.Format(CultureInfo.InvariantCulture, "{0}-{1}", ThreadNamePrefix, i),
                    ThreadPriority,
                    MakeThreadsDaemons);

                workers.Add(wt);
            }

            return workers;
        }
开发者ID:kisflying,项目名称:kion,代码行数:21,代码来源:SimpleThreadPool.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Workflow类代码示例发布时间:2022-05-24
下一篇:
C# Worker类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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