I have an application that uses MEF to load plugins. All of these plugins conform to the following interface:
public interface IPlugin {
Task Start();
}
All the methods are implemented as async
: public async Task Start()
When the application is running I have an IEnumerable<IPlugin>
property available with all the plugins. The question is basically how I can run all the Start()
methods in parallel and wait until all methods are finished?
I know about Parallel.ForEach(plugins, plugin => plugin.Start())
, but this is not awaitable and execution continues before all plugins are started.
The most promising solution seems to be Task.WhenAll()
, but I don't know how to send in an unknown list of methods into this without adding some scaffolding (which seems like overhead).
How can I accomplish this?