Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8542149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:59:27+00:00 2026-06-11T11:59:27+00:00

A third party application is reading the output text file of my windows application,it

  • 0

A third party application is reading the output text file of my windows application,it is getting paused.I think,it is happening because of file gets locked either on writing or reading.how can i make this work fine.Please see my code.

    List<string> fileList = new List<string>();

    System.Timers.Timer timer;

    string currentfilename;
    string currentcontent;

    public Service1()
    {

//

        timer = new System.Timers.Timer();

        timer.AutoReset = false;



        timer.Elapsed += new System.Timers.ElapsedEventHandler(DoStuff);

    }

    void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
        throw new NotImplementedException();
    }

    private void DoStuff(object sender, System.Timers.ElapsedEventArgs e)
    {


     DateTime LastChecked = DateTime.Now;
     try
     {
         string[] files = System.IO.Directory.GetFiles(@"C:\Journal", "*.jrn", System.IO.SearchOption.AllDirectories);

         foreach (string file in files)
         {
             if (!fileList.Contains(file))
             {
                 currentfilename = file;
                 fileList.Add(file);

                     copywarehouse(file);


                 try
                 {


                         string sourcePath = @"C:\Journal";
                         string sourceFile = System.IO.Path.Combine(sourcePath, file);
                         using (FileStream fs= new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                         {
                             StreamReader sr = new StreamReader(fs);
                             currentcontent = sr.ReadToEnd();
                             sr.Close();

                         }


                 }
                 catch (Exception ex)
                 {

                     throw (ex);

                 }


         }


         }

         try
             {


                     string sourcePath1 = @"C:\Journal";
             string currentfilecontent;
                     string sourceFile1 = System.IO.Path.Combine(sourcePath1, currentfilename);

                     using (FileStream fs = new FileStream(sourceFile1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                     {
                         StreamReader sr = new StreamReader(fs);
                         currentfilecontent = sr.ReadToEnd();
                         sr.Close();

                     }





                     if (currentfilecontent != currentcontent)
                     {
                         if (currentfilecontent.Contains(currentcontent))
                         {
                             string originalcontent = currentfilecontent.Substring(currentcontent.Length);


                                 File.WriteAllText(@"C:\Journal\tempfile.txt", originalcontent + "\r\n");
                              using (FileStream fs = new FileStream(@"C:\Journal\tempfile.txt", FileMode.OpenOrCreate))
            {
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(originalcontent);
                sw.Close();
            }

                             currentcontent = currentfilecontent;
                         }
                     }



                 }
             //}

                 catch (Exception ex)
                 {

                     throw (ex);
                 }

         TimeSpan ts = DateTime.Now.Subtract(LastChecked);
         TimeSpan MaxWaitTime = TimeSpan.FromMilliseconds(100);


         if (MaxWaitTime.Subtract(ts).CompareTo(TimeSpan.Zero) > -1)
             timer.Interval = MaxWaitTime.Subtract(ts).Milliseconds;
         else
             timer.Interval = 1;

         timer.Start();



     }



     catch (Exception ex)
     {
         throw (ex);
     }










    }
    private void copywarehouse(string filename)
    {
        string sourcePath = @"C:\Journal";
        string targetPath = @"C:\Journal";

        string copycontent=null;
        try
        {
            string sourceFile = System.IO.Path.Combine(sourcePath, filename);
            string destFile = System.IO.Path.Combine(targetPath, "tempfile.txt");


            using (FileStream fs = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
               StreamReader sr = new StreamReader(fs);

                copycontent = sr.ReadToEnd();
                sr.Close();


            }

            using (FileStream fs = new FileStream(destFile, FileMode.Append))
            {
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(copycontent);
                sw.Close();
            }



        }
        catch (Exception ex)
        {
            throw (ex);
        }




    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:59:27+00:00Added an answer on June 11, 2026 at 11:59 am

    Here the problem is with third party application which is reading my application output as input.it is not allowing access to more than one file content..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to access a third party application's Text Boxes using delphi programming so
I have a windows application which lets say Depends on X third-party application which
I have a third party application that I am installing to my Windows XP
It's a third party application generating huge amounts of log entries on our app
I am writing an app to connect to a third party application using REST
I have to create a user in a third party application that stores its
Is it any way in WIX to detect that a third-party application with a
I've imported 2 dlls to my application (third party) Now both of them have
in my application i am using a third party tool for recording the audio.
In my application I am using a third-party API. It is a non-blocking method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.