title: Windows Service can not open Windows Form
body: <p>I am trying to create a <code>Windows Service</code> using <code>TopShelf</code> and within this service i want to launch a <code>Windows Form</code>.After i created the service and i debugged it calling <code>ShowDialog</code>  the form does not show up:</p>
  
  <p><strong>Service</strong></p>
  
  <pre><code> class SimpleServ {
      private Task task;
      private const string PATH = @"D:/out.txt";
      private Logger logger;
      private CancellationTokenSource src = new CancellationTokenSource();
      public SimpleServ() {
          logger = new Logger();
  
      }
      public void Start() {
  
          logger.Log("Started");
          this.task = Task.Run(async () =&gt; {
  
              var fm = new Fm(logger);
              while (true) {
                  fm.ShowDialog();
                  logger.Log("Just closed the dialog");
                  await Task.Delay(3000);
              }
          });
      }
      public void Stop() {
          logger.Log("Stopped service");
      }
  }
  </code></pre>
  
  <p><strong>Form</strong></p>
  
  <pre><code>public partial class Fm : Form {
      private Logger log;
      public Fm(Logger log) {
          this.log = log;
          this.log.Log("From Form constructor");
          InitializeComponent();
  
      }
  
      private void button1_Click(object sender, EventArgs e) {
          this.log.Log("Button clicked");
          this.Close();
      }
  }
  </code></pre>
  
  <p><strong>Main</strong></p>
  
  <pre><code>class Program {
          static void Main(string[] args) {
              var exitCode = HostFactory.Run(x =&gt; {
                  x.Service&lt;SimpleServ&gt;(s =&gt; {
                      s.ConstructUsing(h =&gt; new SimpleServ());
                      s.WhenStarted(h =&gt; h.Start());
                      s.WhenStopped(h =&gt; h.Stop());
                  });
                  x.RunAsLocalSystem();
                  x.SetServiceName("SimpleService");
                  x.SetDisplayName("Simple Service");
                  x.SetDescription("Simple serv description");
  
              });
              int exitCodeValue = (int)Convert.ChangeType(exitCode, exitCode.GetTypeCode());
              Environment.ExitCode = exitCodeValue;
          }
      }
  </code></pre>
  
  <p>I have attached myself to the service and after it reaches the line of <code>ShowDialog</code> nothing happens.</p>
  
  <p><strong>Update</strong><br>
  I have also added a <code>Logger</code> to log all important events and so far , it seems the form opens but i can not see it:</p>
  
  <p><strong>Logger</strong></p>
  
  <pre><code>public class Logger {
          private string path;
          public Logger(string logPath=Constants.PATH) {
              this.path = logPath;
          }
          private object @lock = new object();
          public void Log(string message) {
              string formattedMessage = "Date:" + DateTime.Now.ToString() + "\tMessage:" + message;
              File.AppendAllLines(this.path, new string[] { formattedMessage });
          }
      }
  </code></pre>
  
  <p>The output of the file is :</p>
  
  <pre><code>Date:6/12/2019 11:19:13 AM  Message:Started
  Date:6/12/2019 11:19:13 AM  Message:From Form constructor
  </code></pre>