Solved

File sharing problem with another program

Posted on 2011-03-03
6
229 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

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

Accepted Solution

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

Author Closing Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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!
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now