本文整理汇总了C#中IScheduler.ScheduleRecurringAction方法的典型用法代码示例。如果您正苦于以下问题:C# IScheduler.ScheduleRecurringAction方法的具体用法?C# IScheduler.ScheduleRecurringAction怎么用?C# IScheduler.ScheduleRecurringAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScheduler
的用法示例。
在下文中一共展示了IScheduler.ScheduleRecurringAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WatchFile
/// <summary>
/// A simpler alternative to the irritatingly useless FileSystemWatcher
/// </summary>
/// <param name="file">The file to monitor</param>
/// <param name="refreshPeriod">The refresh period.</param>
/// <param name="scheduler">The scheduler.</param>
/// <returns></returns>
public static IObservable<FileNotification> WatchFile(this FileInfo file, TimeSpan? refreshPeriod = null,
IScheduler scheduler = null)
{
return Observable.Create<FileNotification>(observer =>
{
var refresh = refreshPeriod ?? TimeSpan.FromMilliseconds(250);
scheduler = scheduler ?? Scheduler.Default;
FileNotification notification = null;
return scheduler.ScheduleRecurringAction(refresh, () =>
{
try
{
notification = notification == null
? new FileNotification(file)
: new FileNotification(notification);
observer.OnNext(notification);
}
catch (Exception ex)
{
notification = new FileNotification(file, ex);
observer.OnNext(notification);
}
});
}).DistinctUntilChanged();
}