title: How to keep thread alive throughout the windows application c#
body: <p>I am using thread which will receive messages from the 
  external application.So my thread shud be alive always.</p>
  
  <p>I want my thread to be running through out the application, 
  untill application exits. Currently i am calling my thread in program.cs, 
  which is the startup for windows application c#. Please see the code below 
  to know how i am doing it.</p>
  
  <p>When i use the below code, the thread starts up when 
  application starts...But it aborts some how, after the thread recieves
   one message from the external application.</p>
  
  <p>I hope i am clear with my questio. Please help. Thanks.</p>
  
  <hr>
  
  <pre><code>  static void Main()
      {
          Application.EnableVisualStyles();
          Application.SetCompatibleTextRenderingDefault(false);
          StartThread();
          Application.Run(new Screensaver());
      }
      public static void StartThread()
      {
              DeamonEngine Deamon = new DeamonEngine();
              Thread ThreadReciever = new Thread(Deamon.Receiver);
              if (!(ThreadReciever.IsAlive))
              {
                  ThreadReciever.Start();
              }
          }
      }
  </code></pre>
  
  <hr>
  
  <p>From a comment:</p>
  
  <pre><code>    void Receiver() { 
          try { 
              Initiate socket s; 
              Bind Ip address; 
              s.Receiver[bytes]; 
              Access the members of message received in bytes;
              Assign the members of message to local variable;
              Read Xml File, get the node values and write to batch file; 
              Execute batch file. 
          } 
          catch { } 
      }
  </code></pre>