I want to run initializations of some objects asynchronously, but some objects depend on others being initialized. And then all objects need to be initialized before the rest of my application continues.
Is it possible to call Wait() on a task and later call Wait() on it again, or as in my example WaitAll() on a collection where it is included?
Dictionary<String, Task> taskdict = new Dictionary<String, Task>( );
taskdict.Add( "Task1",
Task.Factory.StartNew( ( ) => {
//Do stuff
} ) );
taskdict.Add( "Task2",
Task.Factory.StartNew( ( ) => {
taskdict[ "Task1" ].Wait( );
//Do stuff
} ) );
try {
Task.WaitAll( taskdict.Values.Convert<Task[ ]>( ) );
}
Or will that second Wait() / WaitAll() fail?