I'm listing my named pipes using this code:
private IEnumerable<string> GetNamedPipesList()
{
string[] listOfAllPipes = Directory.GetFiles(@"\\.\pipe\");
return listOfAllPipes.Where(pipe => pipe.Contains("FST"));
}
It works fine. I can display them:
private void Scan_Click(object sender, EventArgs e)
{
IEnumerable<string> fsbPipes = GetNamedPipesList();
tbxOutput.Text = string.Empty;
foreach (string fsbPipe in fsbPipes)
{
var pipe = fsbPipe.Replace(@"\\.\pipe\", "");
tbxOutput.AppendText(pipe + Environment.NewLine);
}
}
Examples:
FST-MT4_Miroslav-130
FST-MT4_Miroslav-150
FST-MT4_Miroslav-120
After that I want to close them by deleting like files:
private void CloseAll_Click(object sender, EventArgs e)
{
IEnumerable<string> myPipes = GetNamedPipesList();
foreach (string pipe in myPipes)
{
try
{
File.Delete(pipe);
}
catch (Exception exception)
{
tbxOutput.AppendText(exception.Message + Environment.NewLine);
}
}
}
But it returns The parameter is incorrect. I'm not sure that I can do it, but I had to try since I loaded them as files.
How I can close these named pipes?