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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:02:49+00:00 2026-05-13T17:02:49+00:00

For instance, a thread that is a BackgroundWorker, can be cast like: private void

  • 0

For instance, a thread that is a BackgroundWorker, can be cast like:

private void worker_DoWork(object sender, DoWorkEventArgs e)
    {
        System.ComponentModel.BackgroundWorker senderWorker
                = sender as System.ComponentModel.BackgroundWorker;
    } 

The code above represents what I have for my Background worker thread. I cast [sender] as a BackGround Worker – because I know thats what he is.

I can’t seem to find what I should cast it to if: instead of a Background worker, what if I had used a Process class, and executed say a DOS batch file, using:

enter code here

Process proc = new Process();
proc.FileName = “some_dos_batch_file.bat”;
proc.Exited = ProcessExited;
proc.Start();

Sorry about syntax, but when this process completes, its completion will be handled by ‘ProcessExited’ below. But What should I cast the sender arg to in THAT case – NOT a Background Worker obviously, but I’m not sure to what? I would like to use the .Results property the same as I did for the Background worker.

Thanks – sorry for the confusion.

enter code here




    void ProcessExited(object sender, EventArgs e)

    {
     }
  • 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-13T17:02:49+00:00Added an answer on May 13, 2026 at 5:02 pm

    I hope I have understood your question, if not, please clarify. If you are talking about threading and using the System.Diagnostics.Process then you would need to use Thread events…consider this below a simple class called TestARP that shells out to the command line using a hidden window to retrieve the MAC/IP address of the active connection, with the output of the command redirected to a stream which is appended to a stringbuilder instance:

    public class TestARP
    {
        private StringBuilder sbRedirectedOutput = new StringBuilder();
        public string OutputData
        {
            get { return this.sbRedirectedOutput.ToString(); }
        }
        public void Run()
        {
            System.Diagnostics.ProcessStartInfo ps = new System.Diagnostics.ProcessStartInfo();
            ps.FileName = "arp";
            ps.ErrorDialog = false;
            ps.Arguments = "-a";
            ps.CreateNoWindow = true;
            ps.UseShellExecute = false;
            ps.RedirectStandardOutput = true;
            ps.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    
            using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
            {
                proc.StartInfo = ps;
                proc.Exited += new EventHandler(proc_Exited);
                proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived);
                proc.Start();
                proc.WaitForExit();
                proc.BeginOutputReadLine();
                while (!proc.HasExited) ;
            }
        }
    
        void proc_Exited(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("proc_Exited: Process Ended");
        }
    
        void proc_OutputDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
        {
            if (e.Data != null) this.sbRedirectedOutput.Append(e.Data + Environment.NewLine);
            //System.Diagnostics.Debug.WriteLine("proc_OutputDataReceived: Data: " + e.Data);
        }
    }
    

    If you were to run this in a thread the Process’s events will still get caught (only on the thread itself), but if you’re talking about waiting for the thread to finish, look at this class code here called ThreadTestARP that runs the above class on a thread…

    public class ThreadTestARP
    {
        private TestARP _testARP = new TestARP();
        private ManualResetEvent _mre = new ManualResetEvent(false);
        public ThreadTestARP()
        {
        }
        public TestARP ARPTest
        {
            get { return this._testARP; }
        }
        public void Run()
        {
            Thread t = new Thread(new ThreadStart(RunThread));
            t.Start();
            this._mre.WaitOne();
            // Blocks here...
            t.Join();
        }
        private void RunThread()
        {
            this._testARP.Run();
            this._mre.Set();
        }
    }
    

    Note how the ManualResetEvent _mre is used to signal to say in the context of the thread, “right, I am done, back to the creator…”

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

Sidebar

Ask A Question

Stats

  • Questions 369k
  • Answers 369k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As long as you are sure the snippet contains just… May 14, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer You can use ADO. Here are some notes. ''Must use… May 14, 2026 at 6:27 pm
  • Editorial Team
    Editorial Team added an answer Address already in use: JVM_Bind means that some other application… May 14, 2026 at 6:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.