public Task Create(BackgroundServerContext context, CancellationToken token) { return(Task.Run(() => { throw new CreateException(); }, token)); }
public Task Create(BackgroundServerContext context, CancellationToken token) { return(Task.Factory.StartNew(() => { int filesGenerated = 0; while (!token.IsCancellationRequested) { string fileName = Path.Combine(_settings["Directory"], $"{Path.GetRandomFileName()}.psd"); var file = new FileInfo(fileName); using (StreamWriter writer = file.CreateText()) { const int oneMegaByte = 1024 * 1024; writer.WriteAsync(new string('A', oneMegaByte)).Wait(token); } if (++filesGenerated > 200) { break; } //token.WaitHandle.WaitOne(TimeSpan.FromMilliseconds(500)); } }, token)); }
public Task Create(BackgroundServerContext context, CancellationToken token) { return(Task.Run(() => { _bus(); token.WaitHandle.WaitOne(); }, token)); }
public Task Create(BackgroundServerContext context, CancellationToken token) { return(Task.Run(() => { using (_factory.Create()) { token.WaitHandle.WaitOne(); } }, token)); }
public Task Create(BackgroundServerContext context, CancellationToken token) { return(Task.Factory.StartNew(() => { int iterationCount = 0; while (!token.IsCancellationRequested) { context.Console.WriteLine($"{nameof(MyOtherServer)}: Iteration#: {++iterationCount}"); token.WaitHandle.WaitOne(TimeSpan.FromSeconds(2)); } }, token)); }
public Task Create(BackgroundServerContext context, CancellationToken token) { DirectoryInfo path = PathToMonitor(); if (!path.Exists) { throw new DirectoryNotFoundException($"Cannot watch path {path.FullName}. The directory does not exist."); } string filterLocal = Filter; bool includeSubDirectoriesLocal = IncludeSubDirectories; return(Task.Run(() => { var events = new BlockingCollection <FileSystemEventArgs>(); try { using (var watcher = new FileSystemWatcher(path.FullName, filterLocal)) { watcher.Error += (sender, args) => throw args.GetException(); NotifyFilters notifyFiltersLocal = watcher.NotifyFilter; ChangeNotifyFilters(change => notifyFiltersLocal = change); watcher.NotifyFilter = notifyFiltersLocal; watcher.IncludeSubdirectories = includeSubDirectoriesLocal; if (WatchCreated) { watcher.Created += (sender, args) => events.Add(args, token); } if (WatchRenamed) { watcher.Renamed += (sender, args) => events.Add(args, token); } if (WatchDeleted) { watcher.Deleted += (sender, args) => events.Add(args, token); } if (WatchChanged) { watcher.Changed += (sender, args) => events.Add(args, token); } AddManualFileSystemEventArgs( path, watcher.Filter, watcher.IncludeSubdirectories, watcher.NotifyFilter, fileEvent => events.Add(fileEvent, token)); // Start watcher watcher.EnableRaisingEvents = true; while (!token.IsCancellationRequested) { FileSystemEventArgs fileEvent = events.Take(token); Process(fileEvent); } } } catch (OperationCanceledException) { // BlockingCollection throws this, if the Thread is canceled. } }, token)); }
public Task Create(BackgroundServerContext context, CancellationToken token) { return(_state.TaskToReturn(_waitBlock)); }
public Task Create(BackgroundServerContext context, CancellationToken token) { return(_bot.Worker); }
public Task Create(BackgroundServerContext context, CancellationToken token) { // Will fail from start - but the LiteServer will still run throw new NotImplementedException(); }
public Task Create(BackgroundServerContext context, CancellationToken token) { return(_queue.Consumer); }