Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File sharing problem with another program

Posted on 2011-03-03
6
Medium Priority
?
240 Views
Last Modified: 2012-05-11
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.
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

Open in new window

0
Comment
Question by:dadadude
  • 5
6 Comments
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 35031389
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...
0
 

Author Comment

by:dadadude
ID: 35031434
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.
0
 

Author Comment

by:dadadude
ID: 35031468
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dadadude
ID: 35031655
what happens if i find an answer to my question?
what should i do?
0
 

Accepted Solution

by:
dadadude earned 0 total points
ID: 35034534
I found a solution. Had to fix a line.
Thanks.
0
 

Author Closing Comment

by:dadadude
ID: 35081168
oh thank u for the A. Oh u are welcome lol . silly forum sick of it
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question