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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:14:38+00:00 2026-05-19T11:14:38+00:00

How to make unclosed application in C#? I want to disable the ‘X’ button

  • 0

How to make unclosed application in C#? I want to disable the ‘X’ button of the form and prevent the Windows Task Manager from closing it as well.

I know that one way to prevent a form from closing is to handle the FormClosing event, but how do I prevent the task manager from closing it?

  • 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-19T11:14:39+00:00Added an answer on May 19, 2026 at 11:14 am

    No, it is not possible to prevent Task Manager from closing your application. Task Manager can forcibly terminate a process that is not responding; it doesn’t need the application’s permission to close it, and it doesn’t ask nicely, either. (See this answer for more on Task Manager, and a comparison between the different ways that an application can be closed.)

    The only conceivable workaround is to have two processes, each of them configured to detect when the other one is closed and start up a new instance. Of course, this still won’t stop one of the processes from being killed, it will just allow you to restart it. And this probably falls into the category of user-hostile behavior. If I’ve resorted to using the Task Manager to close your app, I probably want it gone, no matter what you as the programmer intended. And I’m guaranteed to be mad if it keeps spinning up new processes (also likely to be mad is my virus scanner, because it’s seen this kind of behavior before).

    I recommend that you reconsider your application’s design. If you need something that runs all the time in the background, you should be creating a Windows Service. Of course, services don’t have a user interface, and it appears that your application requires one. So better yet, write your code defensively: Save the application’s state so that it can be closed and restored at will. You have to handle the case where the computer is shutting down anyway, so how hard is it to handle just your app being shut down?

    As Microsoft’s Raymond Chen would tell you, Windows doesn’t have a mechanism for this because no one could have imagined an app as awesome as yours that no user would ever want to close.


    As far as disabling your form’s close box, the close icon in the system/window menu, and the Alt+F4 keystroke, this is relatively straightforward. You’ll need to override your form’s CreateParams property, and set the CS_NOCLOSE window class style:

    protected override CreateParams CreateParams
    {
       get
       {
          const int CS_NOCLOSE = 0x200;
    
          CreateParams cp = base.CreateParams;
          cp.ClassStyle |= CS_NOCLOSE;
          return cp;
       }
    }
    

    Compile and run. You’ll get a form that looks like this (note the disabled close button on the titlebar and the absence of a “Close” menu item in the system/window menu):

         Form with CS_NOCLOSE style

    Note that when doing this, you should really provide an alternative mechanism within your application’s interface to close the form. For example, on the “master” form from which this dialog was displayed.

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

Sidebar

Related Questions

I Make a J2ME Application and I just want to print the system date
I make code to display multiple pages (max. 5 lines/page) with persons from one
I make a j2me application that almost all of it, are text files. size:
I make multiple queries to my DB from my python code that uses pyodbc
1 to make an application, and everything's been working fine so far. However, out
I have an ASP.NET application which will be running in a web server (Windows
A unclosed div problem almost make me crazy. It is very difficult to track
I make an iframe application for a fan page, the problem is that if
I make iphone application. I use for root controller tab bar controller. One of
I make this call in my application.js file but it doesn't seem to return

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.