What is the correct way of keeping a Task alive and all Subscriptions active without spinning?
سؤال
I have the following TPL Task
public abstract class AggregatorBase : IAggregator
{
public void Start(CancellationToken token)
{
var parent = Task.Factory.StartNew(x =>
{
Aggregate(token);
},TaskCreationOptions.LongRunning, token);
parent.Wait();
}
public abstract void Aggregate(CancellationToken ct);
}
within the Aggregate method implementations I have a number of Observable.Subscription's ending with the following
public override void Aggregate(CancellationToken ct)
{
this.observables.Subscribe(// Do stuff);
this.observables.Subscribe(// Do more stuff);
while (!token.IsCancellationRequested)
{
System.Threading.Thread.Sleep(1000)
}
}
Question is whats the best way of keeping the Task alive and all Subscriptions active without spinning?
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow