本文整理汇总了C#中Subject.TimeInterval方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.TimeInterval方法的具体用法?C# Subject.TimeInterval怎么用?C# Subject.TimeInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.TimeInterval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TimeBetweenCalls
public void TimeBetweenCalls()
{
var received = new List<String>();
var events = new Subject<String>();
events.TimeInterval().Where(t => t.Interval.TotalMilliseconds > 100).Subscribe(s => received.Add(s.Value));
events.OnNext("too");
events.OnNext("fast");
Thread.Sleep(120);
events.OnNext("slow");
Thread.Sleep(120);
events.OnNext("down");
Assert.AreEqual("slow down", String.Join(" ", received));
}
示例2: Run1
void Run1()
{
/*
disposable?.Dispose();
done.Text = "Working...";
var now = new DateTimeOffset(0, TimeSpan.FromTicks(0)) + TimeSpan.FromMinutes(10);
var sequences = Program.GetStuff2();
Func<Thing, Thing, int> comparer = OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare;
var stuff = new TrackingCollection<Thing>(sequences,comparer,
(t, idx, col) => idx >=5 && idx < 10
//&& t.CreatedAt > now && t.CreatedAt <= (now + TimeSpan.FromMinutes(10))
);
//list.ItemsSource = stuff;
disposable = stuff.Subscribe(() =>
{
bool bad = false;
//stuff.SetComparer(OrderedComparer<Thing>.OrderBy(x => x.Number).Compare);
for (int i = 0; i < stuff.Count - 1; i++)
{
if (comparer(stuff[i], stuff[i + 1]) > 0)
{
bad = true;
break;
}
}
if (bad)
done.Text = "Problem";
else
done.Text = "Done";
});
*/
var seq = Program.GetStuff(50);
//var col = new TrackingCollection<Thing>(
// OrderedComparer<Thing>.OrderByDescending(x => x.UpdatedAt).Compare);
//var res = col.Listen(seq);
//col.ProcessingDelay = TimeSpan.FromMilliseconds(20);
//col.CollectionChanged += (s, ee) => {
// //Console.WriteLine(ee.Action);
// ee.NewItems?.OfType<Thing>().All(thing => { Console.WriteLine("{0} {1}:{2}", ee.Action, thing.Number, thing.UpdatedAt); return true; });
//};
list.ItemsSource = col;
//res.TimeInterval()
// .Select(i => log.Text += i.Interval + "\r\n")
// .Subscribe();
Subject<DateTime> times = new Subject<DateTime>();
var count = 0;
double time = 0;
times.TimeInterval().Do(i =>
{
count++;
time += i.Interval.TotalMilliseconds;
log.Text += i.Interval + "\r\n";
}).Subscribe(_ => { }, () => Debug.WriteLine("AVERAGE " + time / count));
var res = col.Listen(seq);
Debug.WriteLine("===== GO ======");
col.OriginalCompleted.Subscribe(_ => { }, () => times.OnCompleted());
col.Subscribe(x => times.OnNext(DateTime.Now), () => times.OnCompleted());
//seq.Subscribe();
//foreach (var x in seq.ToEnumerable())
//{
// col.AddItem(x);
//}
}