views:

288

answers:

6

How do you disable closing an application when it is not responding and just wait till it recovers back?

+1  A: 

You can always terminate applications from task manager if you have the privileges. You can just disable or not show the system menu options that has the close icon and close menu option in the application window but that is not going to prevent the user from terminating it from task manager as mentioned before. Instead, I would just show some busy processing icon in the application so the user understands what is going on.

msvcyc
+2  A: 

Have the GUI work in a separate thread so that it is (hopefully) never "not responding".

kwatford
I agree. If your program is "not responding" you are doing something wrong.
Talljoe
+5  A: 

What you're asking is not just impossible (any user with sufficient priviledges can terminate a process...no matter what OS), it's a horrible User Experience (UX) decision.

Think about it from the User's point of view. You're sitting there looking at an application. The application doesn't appear to be doing anything and isn't providing you any visual feedback that it is doing work. You'd think the application was hung and you'd restart it.

You could do anything from showing a scrolling progress bar to having the long running process update some piece of information on the UI thread (think of an installer in mid-install...it's constantly telling you which files it's putting where rather than just making you wait). In any case, you should be providing some visual feedback to the user so they know your application is still running.

Justin Niessner
+2  A: 

If this is a question about programming, your program should never be in that state since you've tied up the GUI thread somehow. And you can't (and shouldn't) stop Windows or the user from closing your program. They've detected your code is rubbish and have every right to forcefully toss it out of their valuable address space.

In any case, your program's too busy doing other stuff - if it can't respond to the user, it probably can't waste time protecting itself either.

At some point, developers need to get it through their thick skulls that the computer belongs to the user, not them.

Of course, if you're talking about how to configure Windows to prevent this (such as on your PC), then this question belongs on serverfault.

paxdiablo
+1  A: 

Don't. No matter how important you think your application is, your users' ability to control their own systems is more important.

Tom
A: 

Only thing you can do is disable the close button. Users can still kill it from task manager or similar tool, to way around that. You could make killing it harder by launching it as a privileged process, but that comes with many more problems of its own.

Roel