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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:55:02+00:00 2026-06-17T13:55:02+00:00

Here is my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

  • 0

Here is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Timers;
using System.Diagnostics;

using System.Threading;

namespace ConsoleApplication2 {
    class Program {

        public static System.Timers.Timer aTimer;
        public static System.Diagnostics.Stopwatch sw;
        public static Boolean HasNotepadclosed;
        public static Process pr;

        static void Main(string[] args) {

            Boolean HasNotepadclosed = false;
            sw = new Stopwatch();

            pr = new Process();
            pr.StartInfo = new ProcessStartInfo(@"notepad.exe");
            pr.EnableRaisingEvents = true;
            pr.Exited += new EventHandler(YouClosedNotePad);
            pr.Start();


            aTimer = new System.Timers.Timer();
            aTimer.Interval = 500;
            aTimer.Elapsed += new ElapsedEventHandler(myGong);
            GC.KeepAlive(aTimer);

            Thread myFirstThread;
            myFirstThread = new Thread(new ThreadStart(HelloFirstThread));
            myFirstThread.Start();

            sw.Start();
            aTimer.Enabled = true;

            Console.WriteLine("press [enter] to exit");
            Console.ReadLine();
        }

        static void HelloFirstThread() {
            Console.WriteLine("we're in here now");
            Thread.Sleep(7000);
            if(HasNotepadclosed) {
                Console.WriteLine("bye bye: notepad open");
            } else {
                Console.WriteLine("bye bye: notepad closed");
            }

        }


        static void YouClosedNotePad(object sender, EventArgs e) {
            Console.WriteLine("thanks for closing notepad");
            HasNotepadclosed = true;
        }
        static void myGong(object sender, ElapsedEventArgs e) {
            Console.WriteLine("hello at {0} milliseconds elapsed = {1}", e.SignalTime, sw.ElapsedMilliseconds);
            if(sw.ElapsedMilliseconds > 4000) {
                aTimer.Dispose();
            }
        }


    }
}

If I close notepad before myFirstThread has finished sleeping then I still get a final answer saying “bye bye: notepad open”. Some how I need to make myFirstThread aware of what is going on in the original thread – is this easily done?

  • 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-17T13:55:03+00:00Added an answer on June 17, 2026 at 1:55 pm

    I would do that in the following way:

    • Pass the Process object to the thread that I need it to be in;
    • Use the WaitForExit methods (possibly with a given timeout value);
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Program { class
Here's my code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.CSharp; using
here is a code : using System; using Nemerle.Collections; using Nemerle.Text; //using Nemerle.Utility; using
here's the code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using
Any help? Here's my code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
First here's the code. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
Alright...I am here looking for some bread crumbs. This is my code: using System;
Here is the my python code using BeautifulSoup. The main issue is with the
I'm using the code here and I want all the functions which call SDL

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.