Solved

File sharing problem with another program

Posted on 2011-03-03
6
234 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
performance tune IIS 10 on win 2016 that only runs one website 4 58
Cant save 3D 4 19
Hey!!!! 1 20
Please explain the parts of these 2 LINQ expressions 3 27
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 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