I'm a bit new to file handling in c# especially when it comes to having a file be accessed by more than one process or application.
My problem is that I am trying to write a string "continue" into a file in one application, then the application starts another process...that reads that string with every iteration of it's loop.
When I want this process to stop I write "stop" into the file from the original application and the called application is supposed to pick up on this and terminate it's loop.
Basically I want am asp.net web app to control a console application's execution.
The problem is that the second application does not read the file and get the proper value.
the calling function in the web app is like this:
protected void startButt_Click(object sender, EventArgs e)
{
using (TextWriter tsw = new StreamWriter(@scriptPath + "running.txt"))
{
tsw.WriteLine("cont");
tsw.Close();
}
Process SECExaminerNewNamesParser = new Process();
SECExaminerNewNamesParser.StartInfo.FileName = @scriptPath +"secexaminernewnamesparser.exe";
SECExaminerNewNamesParser.Start();
scriptStatus.Text = "process running";
isRunning = true;
startScriptButt.Enabled = false;
stopScriptButt.Enabled = true;
}
the looping code in the console application is like this:
while (reader.Read())
{
tr = new StreamReader(@"running.txt");
//Do Stuff
if ((runres = tr.ReadLine()) == "stop")
{
tr.Close();
Console.WriteLine("I should stop");
break;
}
else {
Console.WriteLine(runres);
}
tr.Close();
}
the loop does not even pick up the initial value "cont" set by the calling app. I think it has created another file in memory because it cannot access the one on disk? I don't know. :(
If anyone can help I will be grateful.


Sign In
Create Account


Back to top









