当前位置: 首页>>代码示例>>C#>>正文


C# Worker.Stop方法代码示例

本文整理汇总了C#中Worker.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Worker.Stop方法的具体用法?C# Worker.Stop怎么用?C# Worker.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Worker的用法示例。


在下文中一共展示了Worker.Stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

    public static void Main()
	{
	    var worker = new Worker();
	    worker.Start();
	    Thread.Sleep(1000);
	    worker.Stop();	   
	}
开发者ID:ppatoria,项目名称:SoftwareDevelopment,代码行数:7,代码来源:non-volatile-issue.cs

示例2: Main

 static void Main(string[] args)
 {
     const int tenMinutes = 1000*60*10;
     using (var store = new DocumentStore { Url = ConfigurationManager.AppSettings["RavenUrl"] })
     using (var worker = new Worker(tenMinutes, () => Update(store)))
     {
         store.Initialize();
         worker.Start();
         Console.WriteLine("Press any key to terminate...");
         Console.ReadKey();
         worker.Stop();
     }
 }
开发者ID:alundgren,项目名称:alun-tv,代码行数:13,代码来源:Program.cs

示例3: test_43_thread_attach_detach_contested

	public static int test_43_thread_attach_detach_contested () {
		// Test plan: we want to create a race between the GC
		// and native threads detaching.  When a native thread
		// calls a managed delegate, it's attached to the
		// runtime by the wrapper.  It is detached when the
		// thread is destroyed and the TLS key destructor for
		// MonoThreadInfo runs.  That destructor wants to take
		// the GC lock.  So we create a lot of native threads
		// while at the same time running a worker that
		// allocates garbage and invokes the collector.
		var w = new Worker ();
		Thread t = new Thread(new ThreadStart (w.Work));
		t.Start ();

		for (int count = 0; count < 500; count++) {
			int res = mono_test_marshal_thread_attach (delegate (int i) {
					Thread.Sleep (0);
					return i + 1;
				});
		}
		Thread.Sleep (1000);
		w.Stop ();
		t.Join ();
		return 43; 

	}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:26,代码来源:pinvoke3.cs

示例4: BenchmarkDequeueAndExecute1000Jobs

        public void BenchmarkDequeueAndExecute1000Jobs()
        {
            ManualResetEvent handle = new ManualResetEvent(false);
            Queue<QueueRecord> queue = new Queue<QueueRecord>();
            TestJob job = new TestJob() { SleepDuration = 10 };
            string typeName = JobSerializer.GetTypeName(job.GetType());

            for (int i = 0; i < 1000; i++)
            {
                job.Id = Guid.NewGuid();

                queue.Enqueue(
                    new QueueRecord()
                    {
                        Id = i + 1,
                        ApplicationName = BlueCollarSection.Section.ApplicationName,
                        Data = JobSerializer.Serialize(job),
                        JobName = job.Name,
                        JobType = typeName,
                        QueuedOn = DateTime.UtcNow,
                        QueueName = "*",
                        TryNumber = 1
                    });
            }

            SignalsRecord signals = new SignalsRecord() { QueueNames = "*", WorkerSignal = WorkerSignal.None, WorkingSignal = WorkingSignal.None };

            var transaction = new Mock<IDbTransaction>();

            var repository = new Mock<IRepository>();
            repository.Setup(r => r.BeginTransaction()).Returns(transaction.Object);
            repository.Setup(r => r.BeginTransaction(It.IsAny<IsolationLevel>())).Returns(transaction.Object);
            repository.Setup(r => r.CreateWorking(It.IsAny<WorkingRecord>(), It.IsAny<IDbTransaction>())).Returns((WorkingRecord r, IDbTransaction t) => { r.Id = 1; return r; });
            repository.Setup(r => r.GetWorkingSignals(It.IsAny<long>(), It.IsAny<long?>(), It.IsAny<IDbTransaction>())).Returns(signals);
            repository.Setup(r => r.GetQueued(It.IsAny<string>(), It.IsAny<QueueNameFilters>(), It.IsAny<DateTime>(), It.IsAny<IDbTransaction>()))
                .Returns(
                    () =>
                    {
                        var r = queue.Dequeue();

                        if (queue.Count == 0)
                        {
                            handle.Set();
                        }

                        return r;
                    });

            var factory = new Mock<IRepositoryFactory>();
            factory.Setup(f => f.Create()).Returns(repository.Object);

            var logger = new Mock<ILogger>();

            Stopwatch stopwatch = new Stopwatch();

            using (Worker worker = new Worker(BlueCollarSection.Section.ApplicationName, 1, "Test Worker", QueueNameFilters.Any(), 1, false, factory.Object, logger.Object))
            {
                stopwatch.Start();

                worker.Start();
                handle.WaitOne();
                worker.Stop(false);

                stopwatch.Stop();
            }

            this.TestContext.WriteLine("1,000 jobs with 10ms execution times were dequeued and executed in {0:N3}s.", stopwatch.Elapsed.TotalSeconds);
        }
开发者ID:ChadBurggraf,项目名称:blue-collar,代码行数:68,代码来源:Benchmarks.cs


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