本文整理汇总了C#中Subject.SubscribeOn方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.SubscribeOn方法的具体用法?C# Subject.SubscribeOn怎么用?C# Subject.SubscribeOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.SubscribeOn方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoopbackListener
public LoopbackListener()
{
LoopbackDevice.EnsureActive();
var s = new Subject<Tick>();
s.SubscribeOn(Scheduler.TaskPool);
LoopbackDevice.Tickobserver.Where(Filter).Subscribe(s);
_observer=s;
}
示例2: GrapevineSender
public GrapevineSender(ZmqContext context, string address, IMessageSerializer serializer)
{
_serializer = serializer;
_scheduler = new EventLoopScheduler();
_socket = context.CreateSocket(SocketType.PUB);
_socket.Connect(address);
_messages = new Subject<ZmqMessage>();
_messageDispatcher = _messages
.SubscribeOn(_scheduler)
.ObserveOn(_scheduler)
.Subscribe(msg => _socket.SendMessage(msg));
}
示例3: Main
static void Main(string[] args)
{
byte[] clientArray = new byte[1024];
IPAddress serverAddress = IPAddress.Parse(ConfigurationManager.AppSettings["serverAddress"]);
int serverPort = int.Parse(ConfigurationManager.AppSettings["serverPort"]);
IPEndPoint serverEndPoint = new IPEndPoint(serverAddress, serverPort);
var task = GetConnectedClient(serverEndPoint);
task.Wait();
var client =
Observable
.Repeat(clientArray)
.Consume<byte[], int>(array =>
{
return task.Result.SendToObservable(array, 0, 1024, SocketFlags.None, serverEndPoint);
});
Subject<long> totalClient = new Subject<long>();
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
var clientDisposable =
client.SubscribeOn(ThreadPoolScheduler.Instance)
.ObserveOn(Scheduler.Immediate)
.Subscribe(x =>
{
if (x > 0) totalClient.OnNext(x);
else totalClient.OnCompleted();
});
var oneMega = 1048576;
totalClient
.SubscribeOn(ThreadPoolScheduler.Instance)
.Window(TimeSpan.FromSeconds(1))
.Subscribe(x =>
{
x.SubscribeOn(ThreadPoolScheduler.Instance).Aggregate((seed, incr) => seed + incr)
.Subscribe(sum => Console.WriteLine("client speed: {0}", sum / oneMega));
});
Console.ReadLine();
stopWatch.Stop();
clientDisposable.Dispose();
Console.ReadLine();
}