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

  • Home
  • SEARCH
  • 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 6144229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:37:15+00:00 2026-05-23T18:37:15+00:00

I currently have a big problem, the code below checks for the keyword mp4:production/CATCHUP/

  • 0

I currently have a big problem, the code below checks for the keyword “mp4:production/CATCHUP/” in a file, and if found it will launch an executable, although because it finds multiple (exactly the same) instances of “mp4:production/CATCHUP/” it launches several processes. Is there anyway of restricting this, so that it may stop looking when found one instance?

My code is as follows:

string s = "";
        private void CheckLog()
        {
            bool _found;
            while (true)
            {
                _found = false;
                Thread.Sleep(5000);
                if (!System.IO.File.Exists("Command.bat")) continue;
                using (System.IO.StreamReader sr = System.IO.File.OpenText("Command.bat"))
                {

                    while ((s = sr.ReadLine()) != null)
                    {
                        if (s.Contains("test"))
                        {
                            _found = true;
                            break;
                        }

                    }
                }
                if (_found)
                {
                    // Deletes filename in the log file, as the filename is instead handled by p.start

                    var result = Regex.Replace(s, @"test", string.Empty);

                    s = result;

                    RemoveEXELog(); // Deletes a specific keyword from Command.bat
                    RemoveHostFile();
                    Process p = new Process();
                    p.StartInfo.WorkingDirectory = "dump";
                    p.StartInfo.FileName = "test.exe";
                    p.StartInfo.Arguments = s;

                    p.Start();
                    p.WaitForExit();

                    MessageBox.Show("Operation Successful!");
                    string myPath = @"dump";
                    System.Diagnostics.Process prc = new System.Diagnostics.Process();
                    prc.StartInfo.FileName = myPath;
                    prc.Start();


                    ClearLog(); // Deletes Command.bat and then creates a new empty Command.bat
                    LogTrue();
                }
            }
        }
  • 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-05-23T18:37:16+00:00Added an answer on May 23, 2026 at 6:37 pm

    For this scenario I would use a Singleton class to manage the workflow. The Singleton would manage the equivalent to your _found variable in a global threadsafe manner. All threads would then query this property.

    Something like the following:

    public sealed class Singleton
    {
       private static volatile Singleton instance;
       private static object syncRoot = new Object();
    
    
       private Singleton() {}
    
       public bool Found { get; set; }
    
       public static Singleton Instance
       {
          get 
          {
             if (instance == null) 
             {
                lock (syncRoot) 
                {
                   if (instance == null) 
                      instance = new Singleton();
                }
             }
    
             return instance;
          }
       }
    }
    

    Then your code would be something like the following:

    private void CheckLog()
        {
            //bool _found; //not needed anymore
            while (!Singleton.Instance.Found)
            {
                //_found = false;
                Thread.Sleep(5000);
                if (!System.IO.File.Exists("Command.bat")) continue;
                using (System.IO.StreamReader sr = System.IO.File.OpenText("Command.bat"))
                {
    
                    while ((s = sr.ReadLine()) != null)
                    {
                        if (s.Contains("mp4:production/CATCHUP/"))
                        {
                            Singleton.Instance.Found = true;
                            break;
                        }
    
                    }
                }
                if (Singleton.Instance.Found)
                {
                    // Deletes filename in the log file, as the filename is instead handled by p.start
    
                    var result = Regex.Replace(s, @"rtmpdump", string.Empty);
    
                    s = result;
    
                    RemoveEXELog(); // Deletes a specific keyword from Command.bat
                    RemoveHostFile();
                    Process p = new Process();
                    p.StartInfo.WorkingDirectory = "dump";
                    p.StartInfo.FileName = "test.exe";
                    p.StartInfo.Arguments = s;
    
                    p.Start();
                    p.WaitForExit();
    
                    MessageBox.Show("Operation Successful!");
                    string myPath = @"dump";
                    System.Diagnostics.Process prc = new System.Diagnostics.Process();
                    prc.StartInfo.FileName = myPath;
                    prc.Start();
    
    
                    ClearLog(); // Deletes Command.bat and then creates a new empty            Command.bat
                    LogTrue();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
I am a new to db4o. I have a big problem with persistance of
I have run into a big problem, on my mobile website I have a
I have a problem with an application I'm currently developing. In this program I
The problem mentioned below has been solved and code has been changed to reflect
I have a big problem when I try to rotate my projectiles along with
I currently have an MS Access application that connects to a PostgreSQL database via
I currently have speakers set up both in my office and in my living
I currently have an existing database and I am using the LINQtoSQL generator tool
We currently have a company email server with Exchange, and a bulk email processing

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.