title: where to put a while loop in a system tray application so that loop starts with the app
body: <p>I have created a System Tray Application using Windows Forms Template (Visual C++) in Visual Studio 2008. I have used <code>ContextMenuStrip</code> and <code>NotifyIcon</code>. It's a managed code as I have used the form and Drag/Drop.</p>
  
  <p>I want as soon as this System Tray Application starts, it starts polling for any new USB devices (from a specific vendor) connected. </p>
  
  <p>The logic is ready except I don't know "Where to put this <code>while(1)</code> loop?" </p>
  
  <p>It works fine in a console app that I made but now we want it to be integrated to the system tray app.</p>
  
  <p>Here is the code snippet:</p>
  
  <pre><code>        int numDevices, n = 0;
                  while(1)
          {
  
              Sleep(5000);
              numDevices = usb_find_devices();
              if(connectedDevices &gt; numDevices)
              {
                  enumDevices();
                                      connectedDevices++;
  
              }
          }
  </code></pre>
  
  <p>It would really be appreciable if anyone could suggest me some pointers on how to proceed.</p>