title: C# How to force the wait for the connection to a WCF service
body: <p>I have a service running as local SYSTEM that launches another application with the user credentials. 
  That second app is only a tray icon that shows balloon tips to the user with the string received using the callback method. This second application connects to the WCF in duplex mode.</p>
  
  <p>My problem is that for some reason the connection to the WCF is finalized at the end of the method Main. So I cannot send a callback message to the app right after the execution, included in the last line "kiosk.MyStart(args);". there the callback is still pointing to null.</p>
  
  <p>Any idea how could I solve this issue?</p>
  
  <pre><code>static void Main(string []args)
  {
      if (Environment.UserInteractive)
      {
           // Start the WCf service
           var host = new ServiceHost(typeof(WcfService));
           host.Open();
  
           //Launch the Kiosk Agent which connects to the WCF
           bool ret = ProcessAsUser.Launch("C:\\Program Files (x86)\\KIOSK\\KioskAgent.exe");
           WinService kiosk = new WinService(args);
           // some checks and a welcome message is sent to the user.
           kiosk.MyStart(args);
  
           //...
           //...
      }
  }
  </code></pre>
  
  <p><strong>Edit</strong>: to clarify a bit more, inside kiosk.MyStart method is where I try to execute the callback to show a welcome message, but the callback is still NULL.
  As a result I assume that the client was not properly started for any reason and I launch it once again...</p>
  
  <pre><code>            if (WcfService.Callback != null)
                  WcfService.Callback.UIMessageOnCallback(UIMessage);
              else
                  ProcessAsUser.Launch("C:\\Program Files (x86)\\KIOSK\\KioskAgent.exe");
  </code></pre>