我有以下代码:
class Program
{
static void Main(string[] args)
{
var watcher = new SNotifier(DumpToConsole);
watcher.StartQueue();
Console.ReadLine();
}
private static void DumpToConsole(IList<Timestamped<int>> currentCol)
{
Console.WriteLine("buffer time elapsed, current collection contents is: {0} items.", currentCol.Count);
Console.WriteLine("holder has: {0}", currentCol.Count);
}
}
Run Code Online (Sandbox Code Playgroud)
SNotifier:
public class SNotifier
{
private BlockingCollection<int> _holderQueue;
private readonly Action<IList<Timestamped<int>>> _dumpAction;
public SNotifier(Action<IList<Timestamped<int>>> dumpAction)
{
PopulateListWithStartValues();
_dumpAction = dumpAction;
}
public void StartQueue()
{
PopulateQueueOnDiffThread();
var observableCollection = _holderQueue.ToObservable();
var myCollectionTimestamped = observableCollection.Timestamp();
var bufferedTimestampedCollection = myCollectionTimestamped.Buffer(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3));
using (bufferedTimestampedCollection.Subscribe(_dumpAction)) …Run Code Online (Sandbox Code Playgroud)