/// <summary> /// This method will be called when the capturing packets is in progress /// </summary> void PacketCapturer_CaptureProgressChanged(object sender, TJPacketExporter.CaptureProgressEventArgs e) { this.InvokeIfRequired(() => { pbrCapture.Value = e.NumberOfPacketsProcessed; if (e.NumberOfPacketsProcessed == e.MaxNumberOfPacketsToProcess) { pbrCapture.Value = 0; btnSavePacketCapture.IsEnabled = true; Console.WriteLine("Done exporting packets"); } }); }
/// <summary> /// This method respond to the click event of capture button /// </summary> private void btnSavePacketCapture_Click(object sender, RoutedEventArgs e) { TJPacketExporter.TJPacketExportFormat fmt = (TJPacketExporter.TJPacketExportFormat)cbbSavePacketFormat.SelectedValue; try { int packetsToCapture = Convert.ToInt32(tbxSavePacketNumber.Text); string filename = savePacketCapturedialog.FileName; if (packetsToCapture <= 0) { System.Windows.Forms.MessageBox.Show("Choose a non-negative & non-zero value"); return; } if (filename == "") { System.Windows.Forms.MessageBox.Show("Choose where to save the captured file"); return; } btnSavePacketCapture.IsEnabled = false; pbrCapture.Maximum = packetsToCapture; TJPacketExporter pexp = new TJPacketExporter(); pexp.CaptureProgressChanged += PacketCapturer_CaptureProgressChanged; pexp.StartCapturing(filename, fmt, packetsToCapture); } catch (Exception) { //throw; } }