title: C# wait DLL async method to finish
body: <p>I have a DLL which has <code>public Task&lt;&gt;</code> method which returns <code>return Task.Factory.StartNew(() =&gt; ...)</code>. I am calling it within a program and I want the program to wait for the execution of the task to finish before it continues doing other things. I've added <code>Thread.Sleep(6000)</code> to the DLL to simulate longer execution.</p>
  
  <p>When I'm calling it like this</p>
  
  <pre><code>var invokedTask = myMethod.Invoke(Activator.CreateInstance(myClass), myParams);
  </code></pre>
  
  <p>It just continues with execution (as expected). But then I tried this:</p>
  
  <pre><code>var invokedTask = Task.Factory.StartNew(() =&gt; myMethod.Invoke(Activator.CreateInstance(myClass), myParams));
  invokedTask.Wait();
  </code></pre>
  
  <p>And it doesn't work. How can I make it wait from outside of DLL?</p>