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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:18:06+00:00 2026-05-11T14:18:06+00:00

In a program in c# I have 2 threads apart from the main thread.

  • 0

In a program in c# I have 2 threads apart from the main thread. When the user closes the form I want to terminate one of the threads from the main thread. How do I go about doing so?. Please provide me with the code if possible.

  • 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. 2026-05-11T14:18:07+00:00Added an answer on May 11, 2026 at 2:18 pm

    Please don’t use Thread.Abort as recommended by the other answers so far, unless you want your program to be in an unknown state (see articles by Ian Griffiths and Chris Sells for more info). If closing the form should actually be killing the app, you’re probably okay – but in that case I’d recommend just using background threads anyway, which will automatically die when all foreground threads have terminated.

    From Joe Duffy’s ‘Concurrent Programming in Windows’:

    There are two situations in which thread aborts are always safe:

    • The main purpose of thread aborts is to tear down threads during CLR AppDomain unloads. […]
    • Synchronous thread aborts are safe, provided that callers expect an exception to be thrown from the method. […]

    All other uses of thread aborts are questionable at best. […] While thread aborts are theoretically safer than other thread termination mechanisms, they can still occur at inopportune times, leading to instability and corruption if used without care.

    (Synchronous thread aborts are when the thread aborts itself, rather than being aborted by another thread.)

    For graceful shutdown (without risking getting into odd states) use a flag which is set periodically from the form and checked from the other threads – taking the memory model into account (e.g. either making the flag volatile or using a lock each time you test or set it). See my article on the topic for an example.

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • 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 The approach I use in this situation is to insert… May 12, 2026 at 12:46 am
  • Editorial Team
    Editorial Team added an answer Please see Beginner's Guide to Windows Communication Foundation. It's part… May 12, 2026 at 12:46 am
  • Editorial Team
    Editorial Team added an answer Generally what I do in this situation is make the… May 12, 2026 at 12:46 am

Related Questions

I recently wrote a small number-crunching program that basically loops over an N-dimensional grid
c program compiler gcc I have 3 files. main.c stop_watch.h and stop_watch.c This program
I have a multithreaded server C++ program that uses MSXML6 and continuously parses XML
I am working on an application written in C. One part of the application

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.