本文整理汇总了C#中IScheduler.Schedule方法的典型用法代码示例。如果您正苦于以下问题:C# IScheduler.Schedule方法的具体用法?C# IScheduler.Schedule怎么用?C# IScheduler.Schedule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScheduler
的用法示例。
在下文中一共展示了IScheduler.Schedule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateObservable
public static IObservable<string> CreateObservable(string key, IScheduler scheduler)
{
var observable = Observable.Defer(() =>
{
return Observable.Create<string>(observer =>
{
var connectionFactory = new RedisConnectionFactory();
return connectionFactory.CreateRedisConnection().ContinueWith<IDisposable>(task =>
{
if (task.IsFaulted)
{
observer.OnError(task.Exception);
return Disposable.Empty;
}
return scheduler.Schedule(() =>
{
var connection = task.Result.GetOpenSubscriberChannel();
task.Result.Error += (_, err) => observer.OnError(err.Exception);
connection.Subscribe(key, (header, content) =>
{
if (header == key)
observer.OnNext(Encoding.UTF8.GetString(content));
});
});
});
});
});
return observable;
}
示例2: Connect
public IObservable<Socket> Connect(string host, int port, IScheduler scheduler)
{
return Observable.Create<Socket>(observer =>
{
var disposable = new CompositeDisposable();
var socket = socketFactory();
var socketEvent = socketEventsFactory();
socketEvent.RemoteEndPoint = new DnsEndPoint(host, port);
socketEvent.UserToken = socket;
var disposableEventSubscription = socketEvent.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
{
SendNotificationToObserver(observer, socketEvent);
});
var disposableActions = scheduler.Schedule(() =>
{
if (!socket.ConnectAsync(socketEvent))
{
SendNotificationToObserver(observer, socketEvent);
}
});
disposable.Add(disposableEventSubscription);
disposable.Add(disposableActions);
return disposable;
});
}
示例3: BuildConnectionToken
public IObservable<ConnectionToken> BuildConnectionToken(string host, int port, IScheduler scheduler)
{
return Observable.Create<ConnectionToken>(observer =>
{
var disposable = new CompositeDisposable();
var socket = socketFactory();
var socketEvent = socketEventsFactory();
socketEvent.RemoteEndPoint = new DnsEndPoint(host, port);
socketEvent.SocketClientAccessPolicyProtocol = System.Net.Sockets.SocketClientAccessPolicyProtocol.Tcp;
var connectionToken = new ConnectionToken(socket, socketEvent);
var disposableEventSubscription = socketEvent.Completed.Subscribe(_ =>
{
SendNotificationToObserver(observer, socketEvent, connectionToken);
});
var disposableActions = scheduler.Schedule(() =>
{
if (!socket.ConnectAsync(socketEvent))
{
SendNotificationToObserver(observer, socketEvent, connectionToken);
}
});
disposable.Add(disposableEventSubscription);
disposable.Add(disposableActions);
return disposable;
});
}
示例4: SendMessage
public IObservable<Unit> SendMessage(string message, IScheduler scheduler)
{
return Observable.Create<Unit>(observer =>
{
var disposable = new CompositeDisposable();
var buffer = Encoding.UTF8.GetBytes(message);
connectionToken.SocketEvent.SetBuffer(buffer, 0, buffer.Length);
var disposableCompletedSubscription = connectionToken.SocketEvent.Completed.Subscribe(_ =>
{
SendNotificationToObserver(observer, connectionToken.SocketEvent);
});
var disposableActions = scheduler.Schedule(() =>
{
if (!connectionToken.Socket.SendAsync(connectionToken.SocketEvent))
{
SendNotificationToObserver(observer, connectionToken.SocketEvent);
}
});
disposable.Add(disposableCompletedSubscription);
disposable.Add(disposableActions);
return disposable;
});
}
示例5: Receive
public IObservable<string> Receive(Socket connectedSocket, SocketAsyncEventArgs socketEventArgs, IScheduler scheduler, byte[] buffer)
{
if (connectedSocket == null)
throw new ArgumentNullException("connectedSocket");
if (socketEventArgs == null)
throw new ArgumentNullException("socketEventArgs");
return Observable.Create<string>(observer =>
{
var disposable = new CompositeDisposable();
var disposableEventSubscription = socketEventArgs.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
{
SendNotificationToObserver(observer, socketEventArgs);
});
var disposableActions = scheduler.Schedule(() =>
{
socketEventArgs.SetBuffer(buffer, 0, buffer.Length);
if (!connectedSocket.ReceiveAsync(socketEventArgs))
{
SendNotificationToObserver(observer, socketEventArgs);
}
});
disposable.Add(disposableEventSubscription);
disposable.Add(disposableActions);
return disposable;
});
}
示例6: StartLoop
private void StartLoop(IScheduler scheduler)
{
//delegate allocations below - but that's fine as it's not really on the "critical path" (polled relatively infrequently) - and it's much more readable this way
scheduler.Schedule(repeatAction => _httpListener.BeginGetContext(ar =>
{
try
{
var httpListenerContext = _httpListener.EndGetContext(ar);
var request = httpListenerContext.Request;
var response = httpListenerContext.Response;
response.StatusCode = 200;
var acceptHeader = request.Headers.Get("Accept");
var acceptHeaders = acceptHeader == null ? null : acceptHeader.Split(',');
var contentType = ScrapeHandler.GetContentType(acceptHeaders);
response.ContentType = contentType;
using (var outputStream = response.OutputStream)
{
var collected = _registry.CollectAll();
ScrapeHandler.ProcessScrapeRequest(collected, contentType, outputStream);
}
response.Close();
}
catch (Exception e)
{
Trace.WriteLine(string.Format("Error in MetricsServer: {0}", e));
}
repeatAction.Invoke();
}, null));
}
示例7: SendMessage
public IObservable<Unit> SendMessage(Socket connectedSocket, SocketAsyncEventArgs socketEventArgs, IScheduler scheduler, string message)
{
if (connectedSocket == null)
throw new ArgumentNullException("connectedSocket");
if (socketEventArgs == null)
throw new ArgumentNullException("socketEventArgs");
return Observable.Create<Unit>(observer =>
{
var disposable = new CompositeDisposable();
var buffer = Encoding.UTF8.GetBytes(message);
var disposableCompletedSubscription = socketEventArgs.CompletedObservable().ObserveOn(scheduler).Subscribe(_ =>
{
SendNotificationToObserver(observer, socketEventArgs);
});
var disposableActions = scheduler.Schedule(() =>
{
socketEventArgs.SetBuffer(buffer, 0, buffer.Length);
if (!connectedSocket.SendAsync(socketEventArgs))
{
SendNotificationToObserver(observer, socketEventArgs);
}
});
disposable.Add(disposableCompletedSubscription);
disposable.Add(disposableActions);
return disposable;
});
}
示例8: SetUp
public void SetUp()
{
_scheduler = new DefaultScheduler(_bus, _taskStorage);
_handler = new ScheduledTaskMessageHandler(_scheduler);
var task = new ScheduledTask{Task = () => { }};
_taskId = task.Id;
_scheduler.Schedule(task);
}
示例9: CreateObservableWithRetry
public static IObservable<string> CreateObservableWithRetry(string key, IScheduler scheduler)
{
return Observable.Create<string>(observer =>
{
return scheduler.Schedule(self =>
{
var observable = CreateObservable(key, scheduler);
var disposable = observable.Subscribe(
message =>
{
observer.OnNext(message);
},
error =>
{
scheduler.Schedule(TimeSpan.FromSeconds(10), self);
});
});
});
}
示例10: Test2
static void Test2(IScheduler scheduler)
{
var myName = "Lee";
scheduler.Schedule(
myName,
(_, state) =>
{
Console.WriteLine("myName = {0}", state);
return Disposable.Empty;
});
myName = "John";
}
示例11: Tail
//public IObservable<string> TailV2(IFile file)
//{
// return ObservableFile.WatchLines(file.GetNativePath(), Encoding.Default);
//}
public IObservable<string> Tail(IFile file, IScheduler scheduler = null)
{
return Observable.Create<string>(subj =>
{
var disposable = new CompositeDisposable();
scheduler = scheduler ?? RxApp.TaskpoolScheduler;
var abortSignal = new ManualResetEvent(false);
disposable.Add(Disposable.Create(() => abortSignal.Set()));
disposable.Add(scheduler.Schedule(abortSignal, (sched, state) =>
{
using (var reader = new StreamReader(
file.GetContent().OpenStream(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
long lastOffset = reader.BaseStream.Length;
if (reader.BaseStream.Length > 0)
{
// Send the last 10 kb of text to the reader.
lastOffset = Math.Max(0, reader.BaseStream.Length - (1024 * 10));
}
while (!state.WaitOne(100))
{
// Idle if file hasn't changed.
if (reader.BaseStream.Length <= lastOffset)
{
if (reader.BaseStream.Length < lastOffset)
{
lastOffset = reader.BaseStream.Length;
}
continue;
}
// Read the data.
reader.BaseStream.Seek(lastOffset, SeekOrigin.Begin);
var delta = reader.BaseStream.Length - lastOffset;
var buffer = new char[delta];
reader.ReadBlock(buffer, 0, buffer.Length);
// Publish the data.
subj.OnNext(new string(buffer));
// Update the offset.
lastOffset = reader.BaseStream.Position;
}
}
return Disposable.Empty;
}));
return disposable;
});
}
示例12: ScheduleTasks
private static string[] ScheduleTasks(IScheduler scheduler)
{
var list = new List<string>();
Action leafAction = () => list.Add("----leafAction.");
Action innerAction = () =>
{
list.Add("--innerAction start.");
scheduler.Schedule(leafAction);
list.Add("--innerAction end.");
};
Action outerAction = () =>
{
list.Add("outer start.");
scheduler.Schedule(innerAction);
list.Add("outer end.");
};
scheduler.Schedule(outerAction);
return list.ToArray();
}
示例13: Test
static void Test(IScheduler scheduler, bool testCancel = false)
{
Console.WriteLine("Before schedule at {0:o}", DateTime.Now);
var token = scheduler.Schedule(
TimeSpan.FromSeconds(1),
() => Console.WriteLine("Inside schedule at {0:o}", DateTime.Now));
Console.WriteLine("After schedule at {0:o}", DateTime.Now);
if (testCancel)
{
Console.WriteLine("Cancel schedule at {0:o}", DateTime.Now);
token.Dispose();
}
}
示例14: Test
static void Test(IScheduler scheduler)
{
Action<Action> work = self =>
{
Console.WriteLine("Running");
self();
};
var token = scheduler.Schedule(work);
Console.ReadLine();
Console.WriteLine("Cancelling");
token.Dispose();
Console.WriteLine("Cancelled");
}
示例15: FolderNode
public FolderNode(string path, IScheduler loadScheduler, IScheduler dispatherScheduler, FolderNode parent)
: base(path, parent)
{
_loadScheduler = loadScheduler;
_dispatherScheduler = dispatherScheduler;
IsLoaded = false;
var directoryInfo = new DirectoryInfo(path);
_name = directoryInfo.Name;
CreatedDate = directoryInfo.CreationTimeUtc;
_loadScheduler.Schedule(LoadChildren);
}