title: Locking main() thread
body: <p>Not exactly sure on the terminology here but here I go basically I have the main() thread of my application that starts and calls two threads, one sets up an event handler to wait for specific registry keys to change, while the other starts a timer to write any changes made to an xml file every 5 mins or so and runs continuously. The issue I have is that once the two methods called are initialized it goes back to main and ends the program. My relevant code sections can be found below, so any help would be appreciated:</p>
  
  <pre><code>static void Main(string[] args)
      {
          runner one = new runner();
          runner two = new runner();
  
          Thread thread1 = new Thread(new ThreadStart(one.TimerMeth));
          Thread thread2 = new Thread(new ThreadStart(two.start));
  
          thread1.Start();
          thread2.Start();
  
          thread1.Join();
          thread2.Join();
      }
  
  public void TimerMeth()
      {
          System.Timers.Timer timer = new System.Timers.Timer();
  
          timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
  
          timer.Interval = 300000;
  
          timer.Enabled = true;
      }
  
      private void OnElapsedTime(object source, ElapsedEventArgs e)
      {
          file write = new file();
          write.write(RegKeys);
      }
  
  public void start()
          {
              if (File.Exists("C:\\test.xml"))
              {
                  file load = new file();
                  RegKeys = load.read(RegKeys);
              }
  
              string hiveid = "HKEY_USERS";
              WindowsIdentity identity = WindowsIdentity.GetCurrent();
              string id = identity.User.ToString();
  
              string key1 = id + "\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Windows Messaging Subsystem\\\\Profiles\\\\Outlook\\\\0a0d020000000000c000000000000046";
              List&lt;string&gt; value1 = new List&lt;String&gt; { "01020402", "test" };
  
              valuechange = new RegistryValueChange(hiveid, key1, value1);
              valuechange.RegistryValueChanged += new EventHandler&lt;RegistryValueChangedEventArgs&gt;(valuechange_RegistryValueChanged);
  
              try
              {
                  valuechange.Start();
  
              }
              catch
              {
                  StreamWriter ut;
                  ut = File.AppendText("C:\\test.txt");
                  ut.WriteLine("error occured in starting management");
                  ut.Close();
              }
  
              file test = new file();
              test.checkfile("C:\\test.xml");
  
          }
  
  void valuechange_RegistryValueChanged(object sender, RegistryValueChangedEventArgs e)
          {
  // deals with the returned values
  }
  </code></pre>
  
  <p>Basically all the code works fine I've been testing it in a windows form application but now I need to run it in a standalone app with no interface in the background and need it to keep writing to the xml file and the change event to stay alive.</p>