本文整理汇总了C#中Scheduler.Schedule方法的典型用法代码示例。如果您正苦于以下问题:C# Scheduler.Schedule方法的具体用法?C# Scheduler.Schedule怎么用?C# Scheduler.Schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scheduler
的用法示例。
在下文中一共展示了Scheduler.Schedule方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Given_schduler_with_some_work
public void Given_schduler_with_some_work()
{
_scheduler = new Scheduler();
_scheduler.Schedule("Foo1", () => Console.WriteLine("Foo1"), TimeSpan.FromMinutes(2));
_scheduler.Schedule("Foo2", () => Console.WriteLine("Foo2"), TimeSpan.FromMinutes(2));
}
示例2: Given_scheduler_with_daily_item
public void Given_scheduler_with_daily_item()
{
var context = new TestSchedulerContext();
_scheduler = new Scheduler(context);
var runsoon = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
var foo1 = JobFactory.Daily("Foo1", () => { Console.WriteLine("Foo1"); foo1_calls += 1; }, runsoon, description: "Description for Foo1");
var foo2 = JobFactory.Daily("Foo2", () => Console.WriteLine("Foo2"), runsoon);
_scheduler.Schedule(foo1);
_scheduler.Schedule(foo2);
_scheduler.Start();
Wait.Until(() => foo1_calls > 0, 30);
context.MoveToTommorrow();
Wait.Until(() => foo1_calls > 1, 30);
context.MoveForwardNDays(2);
Wait.Until(() => foo1_calls > 2, 50);
}
示例3: Given_scheduler_with_some_work
public void Given_scheduler_with_some_work()
{
var ctx = new TestSchedulerContext();
_scheduler = new Scheduler(ctx);
_scheduler.Schedule("Foo1", () => { _foo1WorkDone = true; }, TimeSpan.FromMinutes(10));
_scheduler.Schedule("Foo2", () => { _foo2WorkDone = true; }, TimeSpan.FromMinutes(10));
// Lest ensure that all workitems
// are applicable for schedule
ctx.MoveToTommorrow();
_scheduler.Start();
Wait.Until(() => _scheduler.GatherOveralStats().RunningJobs + _scheduler.GatherOveralStats().ScheduledJobs == 0);
}
示例4: Auction
public Auction(Inbox inbox, Fiber fiber, Scheduler scheduler)
{
_currentBid = 1.00m;
scheduler.Schedule(60000, fiber, () =>
{
inbox.Send(new EndAuction());
});
inbox.Loop(loop =>
{
loop.Receive<Request<AuctionStatus>>(request =>
{
request.Respond(new AuctionStatusImpl
{
CurrentBid = _currentBid,
IsOpen = _open,
});
});
loop.Receive<Request<PlaceBid>>(request =>
{
if (request.Body.MaximumBid <= _currentBid)
{
request.Respond(new OutBidImpl
{
CurrentBid = _currentBid
});
}
else
{
_currentBid = request.Body.MaximumBid;
request.Respond(new BidAcceptedImpl
{
CurrentBid = _currentBid
});
if (_highBidder != null)
{
_highBidder.Send(new OutBidImpl
{
CurrentBid = _currentBid
});
}
_highBidder = request.ResponseChannel;
}
loop.Continue();
});
loop.Receive<EndAuction>(msg =>
{
_open = false;
// _highBidder.Send(new YouWin());
});
});
}
示例5: PollingFileSystemEventProducer
/// <summary>
/// Creates a PollingFileSystemEventProducer
/// </summary>
/// <param name="directory">The directory to watch</param>
/// <param name="channel">The channel where events should be sent</param>
/// <param name="scheduler">Event scheduler</param>
/// <param name="fiber">Fiber to schedule on</param>
/// <param name="checkInterval">The maximal time between events or polls on a given file</param>
/// <param name="checkSubDirectory">Indicates if subdirectorys will be checked or ignored</param>
public PollingFileSystemEventProducer(string directory, UntypedChannel channel, Scheduler scheduler, Fiber fiber,
TimeSpan checkInterval, bool checkSubDirectory)
{
_directory = directory;
_channel = channel;
_fiber = fiber;
_hashes = new Dictionary<string, Guid>();
_scheduler = scheduler;
_checkInterval = checkInterval;
_scheduledAction = scheduler.Schedule(3.Seconds(), _fiber, HashFileSystem);
ChannelAdapter myChannel = new ChannelAdapter();
_connection = myChannel.Connect(connectionConfigurator =>
{
connectionConfigurator.AddConsumerOf<FileSystemChanged>().UsingConsumer(HandleFileSystemChangedAndCreated);
connectionConfigurator.AddConsumerOf<FileSystemCreated>().UsingConsumer(HandleFileSystemChangedAndCreated);
connectionConfigurator.AddConsumerOf<FileSystemRenamed>().UsingConsumer(HandleFileSystemRenamed);
connectionConfigurator.AddConsumerOf<FileSystemDeleted>().UsingConsumer(HandleFileSystemDeleted);
});
_fileSystemEventProducer = new FileSystemEventProducer(directory, myChannel, checkSubDirectory);
}