Solved

File sharing problem with another program

Posted on 2011-03-03
6
236 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
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS2010 Build fails to install 14 101
C# DataTable (in memory) vs SQL Lookups 4 74
Convert VB web project to C# 3 66
Example code 13 42
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 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