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