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


C# Worker.Start方法代码示例

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


在下文中一共展示了Worker.Start方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SingleSecurityManager

 public SingleSecurityManager(ISecurities securities, string secCode)
 {
     SecCode = secCode;
     Security = securities[secCode];
     _worker = new Worker<NewQuoteEventArgs>("[" + SecCode + " worker]");
     _worker.NewEvent += WorkerNewEvent;
     _worker.Start();
     securities.UpdatedEvent += SecuritiesUpdated;
 }
开发者ID:GodVVin,项目名称:trade,代码行数:9,代码来源:SingleSecurityManager.cs

示例3: 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

示例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

示例5: DefaultRetryService

 /// <summary>Parameterized constructor.
 /// </summary>
 /// <param name="loggerFactory"></param>
 public DefaultRetryService(ILoggerFactory loggerFactory)
 {
     _logger = loggerFactory.Create(GetType().Name);
     _worker = new Worker(TryTakeAndExecuteAction, DefaultPeriod);
     _worker.Start();
 }
开发者ID:jaohaohsuan,项目名称:enode,代码行数:9,代码来源:DefaultRetryService.cs


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