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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:32:06+00:00 2026-05-14T21:32:06+00:00

I’m controlling a creaky old FORTRAN simulator from a VB.NET GUI, using redirected I/O

  • 0

I’m controlling a creaky old FORTRAN simulator from a VB.NET GUI, using redirected I/O to communicate with the simulator executable. The GUI pops up a “status” window with a progress bar, estimated time, and a “STOP” button (Button_Stop).

Now, I want the Button_Stop to terminate the simulator process immediately. The obvious way to do this is to call Kill() on the Child Process object. This gives an exception if it’s done after the process has exited, but I can test whether the process is exited before trying to kill it, right?

OK, so I do the following when the button is clicked:

If Not Child.HasExited Then
    Child.Kill()
    Button_Stop.Enabled = False
End If

However, what if the process happens to exit between the test and the call to Kill()? In that case, I get an exception.

The next thing to occur to me was that I can do Button_Stop.Enabled = False in the Process.Exited event handler, and thus prevent the Child.Kill() call in the Button_Stop.Clicked handler. But since the Process.Exited handler is called on a different thread, that still leaves the following possible interleaving:

  1. Child process exits.
  2. Process.Exited fires, calls Invoke to schedule the Button_Stop.Enabled = False
  3. User clicks on Button_Stop, triggering Child.Kill()
  4. Button_Stop.Enabled = False actually happens.

An exception would then be thrown on step 3.

How do I kill the process without any race conditions? Am I thinking about this entirely wrong?

  • 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-14T21:32:07+00:00Added an answer on May 14, 2026 at 9:32 pm

    Simply catch the exception and disable the button in finally:

    Try                    
        Child.Kill()
    Catch ex As Exception 
        MsgBox(ex.ToString())
    Finally
        Button_Stop.Enabled = False
    End Try
    

    Instead of catching all types of exceptions it would of course be better to only catch InvalidOperationException and Win32Exception as these are thrown if the process is terminating or already exited.

    You probably think it is a “bad thing” if exceptions occur in a program and that you should design your program to avoid exceptions at all. However, there are different types of exceptions and exception handling, some being bad design decisions, and others – like this one – being mandatory, as the reason for the exception (i.e. the termination of another process) is out of your control.

    If you want to read further I recommend you Eric Lipperts posts on different kinds of exceptions:

    Fabulous Adventures In Coding: Vexing exceptions

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.