title: UDP receive delay in WinForms application, but not Console application
body: <p>I am currently writing a program that listens on UDP 67 (DHCP).  For some reason, there seems to be a delay of 1-2 minutes to receive datagrams - but only on WinForms.  When executing in a console applications, everything works as intended, with no noticeable delay ( &lt; 10 seconds).  I'm using the identical code for each.</p>
  
  <p><strong>Edit:</strong> Also note, that sometimes the message doesn't come in for over 5 minutes.  Restart the program, it might come in.</p>
  
  <p><strong>Second Edit:</strong> Wireshark shows traffic coming in - but my application doesn't ever get it.</p>
  
  <p>Any ideas?</p>
  
  <p>Console Code:</p>
  
  <pre><code>    private const int listenPort = 67;
      private static void StartListener()
      {
          bool done = false;
          UdpClient listener = new UdpClient(listenPort);
          IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
          try
          {
              while (!done)
              {
                  Console.WriteLine("Waiting for broadcast");
                  byte[] bytes = listener.Receive(ref groupEP);
                  int len = bytes.Length;
              }
          }
          catch (Exception e)
          {
              Console.WriteLine(e.ToString());
          }
          finally
          {
              listener.Close();
          }
      }
      public static int Main()
      {
          StartListener();
          return 0;
      }
  </code></pre>
  
  <p>WinForms Code:</p>
  
  <pre><code>    private const int listenPort = 67;
      public DHCPServer()
      {
          StartListener();
      }
      private void StartListener()
      {
          bool done = false;
          UdpClient listener = new UdpClient(listenPort);
          IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
          try
          {
              while (!done)
              {
                  byte[] bytes = listener.Receive(ref groupEP);
                  int len = bytes.Length;
              }
          }
          catch (Exception e)
          {   
          }
          finally
          {
              listener.Close();
          }
      }
  </code></pre>