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 7411087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:19:58+00:00 2026-05-29T06:19:58+00:00

Each time CurlFile() is called it creates a new object from the ProcessObject class.

  • 0

Each time CurlFile() is called it creates a new object from the ProcessObject class. The ProcessObject object starts the new Process. I want the Process.Exit event in each object to trigger the static event handler in the parent class, but it doesn’t seem to be working for some reason.

class Curl
{
    StringContainer oStrings = new StringContainer();
    private static int _counter = 0;
    private string _curl;

    public Curl()
    {
        //oStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        _curl = oStrings.Curl;
    }

    public void CurlFile(string _arg)
    {
        ProcessObject oProcessObject = new ProcessObject(_arg, _curl);
    }

    private static void oProcess_Exited(object sender, EventArgs e)
    {
        _counter++;
        if (_counter == 1000)
        {
            MessageBox.Show("here");
        }
    }

    private class ProcessObject
    {
        ProcessStartInfo oStartInfo = new ProcessStartInfo();
        Process oProcess = new Process();

        public ProcessObject(string _arg, string _curl)
        {
            oStartInfo.FileName = _curl;
            oStartInfo.Arguments = _arg;
            oProcess.EnableRaisingEvents = true;
            oProcess.Exited += new EventHandler(oProcess_Exited);
            oProcess = Process.Start(oStartInfo);
        }
    }
}
  • 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-29T06:19:59+00:00Added an answer on May 29, 2026 at 6:19 am

    First off, as @Will mentions, you need to keep a reference to your Process objects so they don’t get GC’d. Something like this (code untested):

    class Curl
    {
        internal static List<ProcessObject> _processes = new List<ProcessObject>();
    
        // ....
    
        private static void oProcess_Exited(object sender, EventArgs e)
        {
            var p = sender as Process;
            if (p != null && _processes.Contains(p))
               _processes.Remove(p);
    
            _counter++;
            if (_counter == 1000)
            {
                MessageBox.Show("here");
            }
        }
    
        public ProcessObject(string _arg, string _curl)
        {
            oStartInfo.FileName = _curl;
            oStartInfo.Arguments = _arg;
            oStartInfo.UseShellExecute = false;
            oProcess.EnableRaisingEvents = true;
            oProcess.Exited += new EventHandler(oProcess_Exited);
            oProcess = Process.Start(oStartInfo);
            Curl._processes.Add(oProcess);
        }
    }
    

    Also, as some people have found, the Process class can be spotty about detecting the Exit. I don’t know if this holds true for the Exited event also, but I’d watch out for it and explicitly set UseShellExecute = false; as I have above.

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

Sidebar

Related Questions

I want to output the function name each time it is called, I can
Each time the save() method is called on a Django object, Django executes two
Each time I have to copy paste || from elsewhere when I want to
i want to read two records each time from select query results in PHP
I want to execute one function each time a file gets written with new
I want to change background color each time when my_div recive class 'selected'. So
Each time my webpage is loaded it runs a routine in the page_load event
Each time I click on the map a new marker is placed on the
I am relatively new to C# and each time I begin to work on
The webViewDidFinishLoad message seems to be sent each time any object in the page

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.