dadadude
asked on
File sharing problem with another program
Hello I have file "sign.car" that is being chared by another program.
that's how it works:
I lauch the c# code. And i excute the other program also.
They both depend on this file. And it contains 1 or 0.
If sign = 1. The the program will use it.
Else i will use it.
That's how i wrote it. BUT it is TIME CONSUMING!!!!!!!!!!!
i have to wait 2 SECONDS it is really slowing my work.
that's how it works:
I lauch the c# code. And i excute the other program also.
They both depend on this file. And it contains 1 or 0.
If sign = 1. The the program will use it.
Else i will use it.
That's how i wrote it. BUT it is TIME CONSUMING!!!!!!!!!!!
i have to wait 2 SECONDS it is really slowing my work.
List<Classification> data = new List<Classification>();
while (signe == 1)
{
if (stopW.ElapsedMilliseconds > 2000)
{
StreamReader reader1 = new StreamReader("signe.car");
line = reader1.ReadLine();
signe = Int32.Parse(line);
reader1.Close();
}
else
{
stopW.Start();
}
if (signe == 0)
{
string path = "resultat.car";
string[] lines = File.ReadAllLines(path);
string[,] grid = new string[obs.GetLength(0), 2];
for (int i = 0; i < lines.Length; i++)
{
string[] fields = lines[i].Split('\t');
data.Add(new Classification(Int32.Parse(fields[0]), Int32.Parse(fields[1])));
}//End For
}//END IF
}//End while
I'm not sure what you are asking if you don't want to wait 2 seconds then take that out. If you are writing the file, closing the handle, flushing the handle, etc... and then opening it with a new instance/process/exe/ect.. . and that 2 seconds is needed for all of that to happen you are stuck. Why not just save the file name with a 1 or 0 in the name. Then you just read the name with one process and you open it with the other. Reading a filename into a string is fast. No buffers and such...
ASKER
actually i tried Try and catch didn't work.
And 2 seconds does count if i have a 100*1000 Loop.
i don't know if there is a way to do it without even affecting the other program. Cos the other one is also throwing an exception.
And 2 seconds does count if i have a 100*1000 Loop.
i don't know if there is a way to do it without even affecting the other program. Cos the other one is also throwing an exception.
ASKER
i think that i am stuck cos the other one don't have an exception. and the only solution to know if it used by another process is to try and open it.
ASKER
what happens if i find an answer to my question?
what should i do?
what should i do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh thank u for the A. Oh u are welcome lol . silly forum sick of it