I have a WinForm «Passive View» and a «Controller» where the controller is running a long running function for each element in a list.
I want the following:
- The functions shall run sequentially
- The view mustn't freeze while looping the list and running the functions
- After each function has run, the view shall be updated with the result of the run
The (single-threaded) code looks like this as of now:
View.DateSpan.Workdays.ForEach(
d => {
var processRunInfo = _processRunner.Run( configFile, d );
UdateViewFrom( processRunInfo );
} );
The code above "works" but causes the view to freeze since it uses the very same thread, and it updates the view batch-wise.
Workdays
is an IEnumerable<DateTime>
, and ForEach
does what ForEach
of List<T>
does but is an extension method from MoreLINQ.
_processRunner.Run
runs an external command line application with the arguments supplied.