Can you call Wait () on a job several times?

I want to initialize some objects asynchronously, but some objects depend on the initialization of other objects. And then all the objects must be initialized before the rest of my application continues.

Is it possible to call Wait () for a task and then call Wait () again, or as in my example WaitAll () in the 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 there be a second call to Wait () / WaitAll ()?

+5
source share
1 answer

, , . , , . , , , Wait , , , , .

, , Wait ( , Wait), Wait , , .

+19

All Articles