title: How to use SharpPcap to dump packets fast
body: <p>I'm using SharpPcap to dump packets to a .pcap file. My problem is, that it's working to slow to capture any amount of network traffic and I run out of memory eventually.
  How can i speed up the file writing process?</p>
  
  <p>Here is the code I'm using:</p>
  
  <pre><code>    private void WriteToPCAPThread(object o)
      {
          this.WritePcapThreadDone.Reset();
          string captureFileName = (string)o;
          CaptureFileWriterDevice captureFileWriter = new CaptureFileWriterDevice(this.device, captureFileName);
          captureFileWriter.Open();
          RawCapture packet;
          bool success;
          while (this.capturing)
          {
              success = this.captures.TryDequeue(out packet);
              if (success)
              {
                  captureFileWriter.Write(packet);
              }
              else
              {
                  // Queue emptied
                  Thread.Sleep(50);
              }
          }
      }
  </code></pre>
  
  <p>Thanks in advance for any ideas.</p>