J'ai deux boucles while, que j'aurai exécutées en parallèle avec le TPL.Y at-il une chance de remplacer une boucle while avec le TPL?
Mon code:
public void Initialize()
{
cts = new CancellationTokenSource();
ParallelOptions options = new ParallelOptions();
options.CancellationToken = cts.Token;
options.MaxDegreeOfParallelism = Environment.ProcessorCount;
task = Task.Factory.StartNew(() => Parallel.Invoke(options, Watcher1, Watcher2), cts.Token);
}
public void Watcher1()
{
//Can I replace this (with a TPL construct in the initialize method)?
while(true)
{
//Do sth.
}
}
public void Watcher2()
{
//Can I replace this (with a TPL construct in the initialize method)?
while(true)
{
//do sth
}
}
Ce serait bien, si je peux annuler ces deux actions en toute sécurité. Pouvez-vous me donner quelques conseils?
Merci d'avance.
Meilleures salutations, pro