I build an application that captures and plays Wireshark files and send all the packets to my network card. In the application the user can choose a folder and all the files inside this folder are added to a list box and played in an endless loop. For my application I am using Pcapdotnet DLLs but because of a bug in Wincap that after 500 files the library tries to access the files and the application crashes, I have build an exe file that takes my interface number and file path as arguments. After the file finishes to play the exe file closes so in this case I can play more than 500 files without crashes.
This is my start button who starts to play all the files from my list box: sendQueue is my exe file that i am send the file path
private void btnStart_Click(object sender, EventArgs e)
{
shouldContinue = true;
this.Invoke((MethodInvoker)delegate
{
btnStart.Enabled = false;
btnStop.Enabled = true;
groupBoxAdapter.Enabled = false;
groupBoxRootDirectory.Enabled = false;
});
backGroundWorker = new BackgroundWorker();
backGroundWorker.WorkerReportsProgress = true;
backGroundWorker.DoWork += new DoWorkEventHandler(
(s3, e3) =>
{
for (int i = 0; i < lbFiles.Items.Count && shouldContinue; i++)
{
this.Invoke((MethodInvoker)delegate
{
lbFiles.SetSelected(i, true);
toolStripStatusLabel.Text = string.Format("Playing file no {0} of {1}", i + 1, lbFiles.Items.Count);
});
sendQueue((string)lbFiles.Items[i]);
}
});
backGroundWorker.RunWorkerAsync();
}
What I want to do is stop button to stop my play by changing the shouldContinue boolean variable to false and close all my processes who are playing my file (SendQueue.exe) and my problem is that the process is still running.
bool shouldContinue = true;
private void btnStop_Click(object sender, EventArgs e)
{
shouldContinue = false;
foreach (Process prc in System.Diagnostics.Process.GetProcessesByName("SendQueue"))
{
prc.Kill();
prc.WaitForExit();
}
toolStripStatusLabel.Text = "Stop playing";
}