本文整理汇总了C#中IObservable.ObserveOn方法的典型用法代码示例。如果您正苦于以下问题:C# IObservable.ObserveOn方法的具体用法?C# IObservable.ObserveOn怎么用?C# IObservable.ObserveOn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IObservable
的用法示例。
在下文中一共展示了IObservable.ObserveOn方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExerciseViewModel
public ExerciseViewModel(ISchedulerService schedulerService, Exercise model, IObservable<ExecutionContext> executionContext)
{
schedulerService.AssertNotNull(nameof(schedulerService));
model.AssertNotNull(nameof(model));
executionContext.AssertNotNull(nameof(executionContext));
this.disposables = new CompositeDisposable();
this.model = model;
executionContext
.ObserveOn(schedulerService.MainScheduler)
.Subscribe(x => this.ExecutionContext = x)
.AddTo(this.disposables);
Observable
.CombineLatest(
this
.WhenAnyValue(x => x.ExecutionContext)
.Select(ec => ec == null ? Observable.Never<TimeSpan>() : ec.WhenAnyValue(x => x.SkipAhead))
.Switch(),
this
.WhenAnyValue(x => x.ExecutionContext)
.Select(ec => ec == null ? Observable.Never<Exercise>() : ec.WhenAnyValue(x => x.CurrentExercise))
.Switch(),
(skip, current) => skip == TimeSpan.Zero && current == this.model)
.ObserveOn(schedulerService.MainScheduler)
.Subscribe(x => this.IsActive = x)
.AddTo(this.disposables);
this
.WhenAnyValue(x => x.ExecutionContext)
.Select(
ec =>
ec == null
? Observable.Return(TimeSpan.Zero)
: ec
.WhenAnyValue(x => x.CurrentExerciseProgress)
.Where(_ => ec.CurrentExercise == this.model)
.StartWith(TimeSpan.Zero))
.Switch()
.ObserveOn(schedulerService.MainScheduler)
.Subscribe(x => this.ProgressTimeSpan = x)
.AddTo(this.disposables);
this
.WhenAny(
x => x.Duration,
x => x.ProgressTimeSpan,
(duration, progressTimeSpan) => progressTimeSpan.Value.TotalMilliseconds / duration.Value.TotalMilliseconds)
.Select(progressRatio => double.IsNaN(progressRatio) || double.IsInfinity(progressRatio) ? 0d : progressRatio)
.Select(progressRatio => Math.Min(1d, progressRatio))
.Select(progressRatio => Math.Max(0d, progressRatio))
.ObserveOn(schedulerService.MainScheduler)
.Subscribe(x => this.Progress = x)
.AddTo(this.disposables);
}
示例2: PegCompiler
public PegCompiler(IObservable<Grammar> grammars)
{
var compileResults = grammars
.ObserveOn(Scheduler.Default)
.Select(r => r == null ? new Compiler.CompileResult(r) : Compiler.PegCompiler.Compile(r))
.Publish()
.RefCount();
this.Codes = compileResults.Select(r => r.Code);
this.Errors = compileResults.Select(r => r.Errors.ToList().AsReadOnly());
}
示例3: CsCompiler
public CsCompiler(IObservable<Tuple<string, Grammar>> codeAndGrammar)
{
var csCompilerResults = codeAndGrammar
.ObserveOn(Scheduler.Default)
.Select(p => Compile(p.Item1, p.Item2))
.Publish()
.RefCount();
this.Parsers = csCompilerResults.Select(r => r.Parser);
this.Errors = csCompilerResults.Select(r => r.Errors);
}
示例4: PegParser
public PegParser(IObservable<string> subjects)
{
var internalParseResults = subjects
.ObserveOn(Scheduler.Default)
.Select(Parse)
.Publish()
.RefCount();
this.Grammars = internalParseResults.Select(g => g.Grammar);
this.Errors = internalParseResults.Select(g => g.Errors.AsReadOnly());
this.LexicalElements = internalParseResults.Select(g => g.LexicalElements);
}
示例5: MessagesView
public MessagesView(IObservable<Message> messagesObservable, bool showSendArea = true)
{
_showSendArea = showSendArea;
_items = new ObservableCollection<Message>();
InitView();
_sendButton.Clicked += async (sender, args) => await SendClicked();
_textToSendEntry.Completed += async (sender, args) => await SendClicked();
messagesObservable
.ObserveOn(SynchronizationContext.Current)
.Subscribe(m => _items.Add(m));
}
示例6: Account
public Account(
string login,
bool isUser,
bool isEnterprise,
int ownedPrivateRepositoryCount,
long privateRepositoryInPlanCount,
IObservable<BitmapSource> bitmapSource)
{
Login = login;
IsUser = isUser;
IsEnterprise = isEnterprise;
OwnedPrivateRepos = ownedPrivateRepositoryCount;
PrivateReposInPlan = privateRepositoryInPlanCount;
IsOnFreePlan = privateRepositoryInPlanCount == 0;
HasMaximumPrivateRepositories = OwnedPrivateRepos >= PrivateReposInPlan;
avatar = bitmapSource.ObserveOn(RxApp.MainThreadScheduler)
.ToProperty(this, a => a.Avatar);
}
示例7: Aggregate
private void Aggregate(IObservable<LogEvent> events)
{
Guid g = Guid.NewGuid();
Console.WriteLine(g + " opened at "+ DateTime.Now);
List<LogEvent> allEvents = new List<LogEvent>();
events.ObserveOn(TaskPoolScheduler.Default).Subscribe(
evt => allEvents.Add(evt),
() =>
{
Console.WriteLine(g + " closed at " + DateTime.Now);
var gr = GroupCounters(allEvents);
_aggregationCompleteSubject.OnNext(gr.Select(gouppedValues =>
{
AggregatedValue result =
new AggregatedValue(
gouppedValues.Key,
_aggregationOperation.Do(
gouppedValues.ToList()));
Console.WriteLine(DateTime.Now + " Aggregated on thread #" + Thread.CurrentThread.ManagedThreadId);
return result;
}).ToList());
Console.WriteLine(g + " Finished on thread #" + Thread.CurrentThread.ManagedThreadId+"\r\n"+string.Join("\r\n",allEvents));
});
}
示例8: GetOEmbeds
/// <summary>
/// Gets multiple oEmbeds
/// </summary>
/// <param name="client">The client.</param>
/// <param name="urls">The urls.</param>
/// <param name="providerFilter">The provider filter.</param>
/// <param name="options">The options.</param>
/// <returns></returns>
public static IObservable<Result> GetOEmbeds(this Client client, IObservable<Uri> urls, Func<Provider, bool> providerFilter, RequestOptions options)
{
if (urls == null)
throw new ArgumentNullException("urls");
if (options == null)
throw new ArgumentNullException("options");
var requests = urls
.ObserveOn(NewThreadScheduler.Default)
.Select(u => u.MakeUrlRequests(client))
.WhereProvider(providerFilter);
var redirector = new RequestObserver(client, options);
requests.Subscribe(redirector);
return redirector.Output;
}
示例9: Presenter
public Presenter(IObservable<string[]> models, IScheduler scheduler)
{
TableViewModel = models.ObserveOn (scheduler);
}
示例10: BeginAggregation
public void BeginAggregation(IObservable<IList<LogEventArgs>> observableEvents)
{
UnsubscriptionToken = observableEvents.ObserveOn(Scheduler.Default).Subscribe(AggregationAction);
}
示例11: MouseHover
void MouseHover()
{
// Here create an event stream called mouseGeosWithMouseWheelNulls, which consists of the MouseGeo event stream,
// merged with another stream that produces a null every time the mouse wheel is moved
// Here create an event stream called MouseHoverGeo, which consists of mouseGeosWithMouseWheelNulls events
// filtered to only give us an event after 300 ms of inactivity with duplicate events and null events removed
MouseHoverGeo = MouseGeo.Throttle(TimeSpan.FromMilliseconds(300))
.Merge(Observable.FromEventPattern<MouseWheelEventArgs>(_wpfMap, "MouseWheel").Select(e => (Geo)null))
.Merge(MouseGeo.Select(e => (Geo)null))
.DistinctUntilChanged();
//MouseHoverGeo.ObserveOn(TaskPoolScheduler.Default).Subscribe(g => Debug.WriteLine(string.Format("{0:HH:mm:ss:fff} MouseHoverGeo is now {1}", DateTime.Now, g)));
#if false
// Observe the MouseHoveGeo event stream on the TaskPool
_mouseHover = MouseHoverGeo.ObserveOn(TaskPoolScheduler.Default)
.Subscribe(g =>
{
var pointShape = new PointShape(g.Longitude, g.Latitude);
foreach (var activeLayerOverlay in _wpfMap.Overlays.OfType<ActiveLayerOverlay>().ToList())
{
foreach (var featureLayer in activeLayerOverlay.Layers.OfType<FeatureLayer>().ToList())
{
try
{
featureLayer.Open();
var featureCollection = featureLayer.QueryTools.GetFeaturesContaining(pointShape, ReturningColumnsType.NoColumns);
if (featureCollection.Count == 0) continue;
activeLayerOverlay.MouseIsHovering.OnNext(true);
_hoveringOverlays.Add(activeLayerOverlay);
}
finally
{
if (featureLayer.IsOpen) featureLayer.Close();
}
}
}
});
mouseGeoWithMouseWheelNull.ObserveOn(TaskPoolScheduler.Default)
.Subscribe(g =>
{
while (!_hoveringOverlays.IsEmpty)
{
ActiveLayerOverlay overlay;
if (_hoveringOverlays.TryTake(out overlay)) overlay.MouseIsHovering.OnNext(false);
}
});
#endif
}
示例12: StartTracking
public void StartTracking(IObservable<PlotData> data)
{
var disposable = data.ObserveOn(this).Subscribe(DisplayPlotData);
}