本文整理汇总了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();
}
示例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;
}
示例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();
}
}
示例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);
}
示例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();
}