?
Solved

File sharing problem with another program

Posted on 2011-03-03
6
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 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