I know the foreach loop in the parallel class will "only need to do any expensive cross-thread access when it really needs to." But I like to keep a logger richtextbox that keeps track of all of the different steps as they complete. Is there a way to force the parallel foreach loop to update the control?
public void log(String msg, Color? c = null)
{
logger.BeginInvoke((MethodInvoker)delegate
{
logger.SelectionStart = logger.Text.Length;
logger.SelectionColor = c.HasValue ? c.Value : Color.Black;
logger.AppendText("\n" + msg);
});
}
This thread safe log method will update the logger but only after the entire foreach loop has completed which I don't really like.
so if you have a suggestion on how to force it to update or a better option I would like to hear it.
Edit: Wrapping the parallel foreach loop in Task.Factory.StartNew(() => ); will not block the UI.