本文整理汇总了C#中Subject.ObserveOn方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.ObserveOn方法的具体用法?C# Subject.ObserveOn怎么用?C# Subject.ObserveOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.ObserveOn方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JustUsingSubject
public void JustUsingSubject()
{
Log.WriteLine("Starting ----");
var subject = new Subject<string>();
var scheduler = Scheduler.Immediate;
subject.ObserveOn(scheduler).Subscribe(DoWork);
subject.ObserveOn(scheduler).Subscribe(DoWork);
for (int i = 0; i < 5; i++)
{
new System.Threading.Thread(state =>
{
for (int j = 0; j < 10; j++)
{
System.Threading.Thread.Sleep(0);
subject.OnNext(string.Format("{0} -> {1} ", state, j));
}
}){ Name = "Dispatcher " + i }.Start(string.Format("Thread {0}", i));
}
Log.WriteLine("Ending ----");
System.Threading.Thread.Sleep(1000);
}
示例2: Main
static void Main(string[] args)
{
var bus = RabbitHutch.CreateBus().Advanced;
var exchange = Exchange.DeclareTopic("RCC_RX");
var queue = Queue.DeclareDurable("Worker");
queue.BindTo(exchange, "Task.#");
var stream = new Subject<TodoEvent>();
bus.Subscribe<TodoEvent>(queue, async (msg, info) =>
{
var todoEvent = msg.Body;
Console.WriteLine("Recieved Message");
stream.OnNext(todoEvent);
Console.WriteLine("Pushed to Stream");
});
stream
.ObserveOn(TaskPoolScheduler.Default)
.Where(te => te.Type == EventType.Add)
.Buffer(TimeSpan.FromSeconds(15))
.Where(teList => teList.Count >= 3)
.Do(teList => Console.WriteLine("Productive! {0}", teList.Count))
.Subscribe(teList => NotifyClient("Productive!"));
}
示例3: MainWindow
public MainWindow()
{
InitializeComponent();
counter = 0;
orders = new Subject<OrderSet>();
orders.ObserveOn(SynchronizationContext.Current).Subscribe(x => _items.Items.Add(x));
}
示例4: Receive
public IObservable<string> Receive(byte[] buffer, IScheduler scheduler)
{
return Observable.Create<string>(observer =>
{
var disposable = new CompositeDisposable();
this.connectionToken.SocketEvent.SetBuffer(buffer, 0, buffer.Length);
var subject = new Subject<Unit>();
var disposableEventSubscription = connectionToken.SocketEvent.Completed.Subscribe(_ =>
{
if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
{
subject.OnNext(Unit.Default);
}
});
var disposableActions = subject.ObserveOn(scheduler).Subscribe(_ =>
{
if (!connectionToken.Socket.ReceiveAsync(connectionToken.SocketEvent))
{
if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
{
subject.OnNext(Unit.Default);
}
}
});
subject.OnNext(Unit.Default);
disposable.Add(disposableEventSubscription);
disposable.Add(disposableActions);
return disposable;
});
}
示例5: ParserSelectManyCollection_MovesToEndOfFirstMatch
public void ParserSelectManyCollection_MovesToEndOfFirstMatch()
{
using (var parserCompleted = new ManualResetEventSlim())
using (var source = new Subject<int>())
{
var results = source
.ObserveOn(ThreadPoolScheduler.Instance)
.Parse(parser =>
from next in parser
select from elements in next.Exactly(2)
from value in elements
where value < 2
select value);
var values = new List<int>();
using (results.Subscribe(values.Add, parserCompleted.Set))
{
source.OnNext(2);
source.OnNext(2);
source.OnNext(0);
source.OnNext(1);
source.OnNext(0);
source.OnNext(1);
source.OnCompleted();
parserCompleted.Wait();
Assert.AreEqual(4, values.Count);
}
}
}
示例6: Start
// Use this for initialization
void Start()
{
var scheduler = SchedulerUnity.MainThread;
textOutput.text = "start...";
var c = new Class1();
var s = new Subject<string>();
_disposable = s.ObserveOn(scheduler).Subscribe(
res => textOutput.text = res.Substring(0, 100),
ex => textOutput.text = ex.Message
);
c.RunAsync(s);
}
示例7: WatchListViewModel
// ctor
/// <summary>
/// Initializes a new instance of the <see cref="WatchListViewModel"/> class.
/// </summary>
/// <param name="hostScreen">The host screen.</param>
public WatchListViewModel(IScreen hostScreen)
{
HostScreen = hostScreen ?? Locator.Current.GetService<IScreen>();
DataManager.Current.AppDb
.WatchListItemChange
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(OnWatchListItemChange);
ItemClick = new Subject<WatchListItemViewModel>();
ItemClick
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(OnItemClick);
LoadDefaultStocks();
}
示例8: BindableObject
public BindableObject()
{
changed = new Subject<PropertyChangedData>();
changed.ObserveOn(SchedulerProvider.UIScheduler)
.Subscribe(args =>
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(args.PropertyName));
});
Changed = changed.AsObservable();
changing = new Subject<PropertyChangingData>();
changing.ObserveOn(SchedulerProvider.UIScheduler)
.Subscribe(args =>
{
PropertyChanging?.Invoke(this, new PropertyChangingEventArgs(args.PropertyName));
});
Changing = changing.AsObservable();
}
示例9: Start
void Start()
{
var s = new Subject<string>();
var scheduler = SchedulerUnity.MainThread;
s.ObserveOn(scheduler).Subscribe(
result =>
{
Debug.Log(result);
_textOutput.text += result.Substring(0, Math.Min(result.Length, 100)) + "\n";
},
ex =>
{
Debug.Log(ex);
_textOutput.text += ex.Message + "\n";
}
);
Class1.MainAsync(s);
}
示例10: ObserveOnTest
public void ObserveOnTest()
{
var xs = Observable.Range(1, 10)
.ObserveOn(Scheduler.ThreadPool)
.ToArrayWait();
xs.OrderBy(x => x).IsCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
var s = new Subject<int>();
var list = new List<Notification<int>>();
s.ObserveOn(Scheduler.Immediate).Materialize().Subscribe(list.Add);
s.OnError(new Exception());
list[0].Kind.Is(NotificationKind.OnError);
s = new Subject<int>();
s.ObserveOn(Scheduler.Immediate).Materialize().Subscribe(list.Add);
s.OnCompleted();
list[1].Kind.Is(NotificationKind.OnCompleted);
}
示例11: OnChannelJoined
/// <summary>
/// Executed when the pusher connection with the private user channel
/// is established and we can subscribe to messages.
/// </summary>
/// <param name="userChannel">User channel object</param>
private void OnChannelJoined(Channel userChannel)
{
if (userChannel == null) {
return;
}
// subscribe through a subject so we can do more fun stuff with it
var star = new Subject<JObject>();
var unstar = new Subject<JObject>();
var newReleaseVersion = new Subject<JObject>();
userChannel.Bind("star", data => { star.OnNext(data as JObject); });
userChannel.Bind("unstar", data => { unstar.OnNext(data as JObject); });
userChannel.Bind("new_release_version", data => { newReleaseVersion.OnNext(data as JObject); });
// star
star.ObserveOn(RxApp.MainThreadScheduler)
.Select(msg => StarEvent.GetInstance(msg, true))
.Where(msg => msg.Type == "release")
.Subscribe((Subject<StarEvent>) WhenReleaseStarred);
// unstar
unstar.ObserveOn(RxApp.MainThreadScheduler)
.Select(msg => StarEvent.GetInstance(msg, false))
.Where(msg => msg.Type == "release")
.Subscribe((Subject<StarEvent>) WhenReleaseStarred);
// new release version
newReleaseVersion.ObserveOn(RxApp.MainThreadScheduler)
.Select(NewVersionEvent.GetInstance)
.Subscribe((Subject<NewVersionEvent>)WhenReleaseUpdated);
}
示例12: BitmapBackgroundLoader
static BitmapBackgroundLoader()
{
_numprocessing = 0;
_requestob = new Subject<BitmapRequest>();
_requestob
.ObserveOn(Scheduler.ThreadPool)
.Do(x =>
{
while (_numprocessing >= MAX_SIMULTANEOUS_LOADING_COUNT)
{
Thread.Sleep(SLEEP_TIME);
}
})
.Do(x => ++_numprocessing)
.Do(x => Thread.Sleep(SLEEP_TIME))
.Do(x => Debug.WriteLine("_requestob: Received request - {0}", x.IsoPath))
.Subscribe(GenerateStreamAndPush);
_streamob = new Subject<BitmapRequest>();
_streamob
.Do(x => Thread.Sleep(SLEEP_TIME))
.Do(x => Debug.WriteLine("_streamob: Received request - {0}", x.IsoPath))
.ObserveOnDispatcher()
.Subscribe(GenerateBackgroundBitmapLoadingAndPush);
_requestdoneob = new Subject<BitmapRequest>();
_requestdoneob
.ObserveOn(Scheduler.ThreadPool)
.Do(x => Thread.Sleep(SLEEP_TIME))
.Do(x => Debug.WriteLine("_requestdoneob: Received request - {0}", x.IsoPath))
.Do(x => --_numprocessing)
.Subscribe(NotifyJobDone);
}
示例13: ParserSelectManyCollection_MovesToEndOfFirstMatch_Concurrent
public void ParserSelectManyCollection_MovesToEndOfFirstMatch_Concurrent()
{
using (var artificialRaceCondition = new ManualResetEventSlim())
using (var parserCompleted = new ManualResetEventSlim())
using (var source = new Subject<int>())
{
var results = source
.ObserveOn(ThreadPoolScheduler.Instance)
.Parse(parser =>
from next in parser
select from elements in next.Exactly(2)
from value in elements
.ObserveOn(ThreadPoolScheduler.Instance)
.Do(_ => artificialRaceCondition.Wait())
where value < 2
select value);
var values = new List<int>();
using (results.Subscribe(values.Add, parserCompleted.Set))
{
source.OnNext(2);
source.OnNext(2);
source.OnNext(0);
source.OnNext(1);
source.OnNext(0);
source.OnNext(1);
source.OnCompleted();
artificialRaceCondition.Set();
parserCompleted.Wait();
// TODO: Fix parsers so that this test always passes. For now, we can't assert failure because sometimes the test passes.
// Assert.AreEqual(4, values.Count);
}
}
}
示例14: ParserSelectManyCollection_MovesToEndOfFirstMatch_Nested
public void ParserSelectManyCollection_MovesToEndOfFirstMatch_Nested()
{
using (var artificialRaceCondition = new ManualResetEventSlim())
using (var parserCompleted = new ManualResetEventSlim())
using (var source = new Subject<int>())
{
var results = source
.ObserveOn(ThreadPoolScheduler.Instance)
.Parse(parser =>
from next in parser
select from elements in next.Exactly(2)
from value in
elements.Parse(subparser =>
from subnext in subparser
select subnext.Where(
value =>
{
artificialRaceCondition.Wait();
return value < 2;
}))
select value);
var values = new List<int>();
using (results.Subscribe(values.Add, () => parserCompleted.Set()))
{
source.OnNext(2);
source.OnNext(2);
source.OnNext(0);
source.OnNext(1);
source.OnNext(0);
source.OnNext(1);
source.OnCompleted();
artificialRaceCondition.Set();
parserCompleted.Wait();
Assert.AreEqual(4, values.Count);
}
}
}