473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Prevent Windows from closing an application

I want to prevent a user from closing an application while doing critical
operations. The following code (concept came from MSDN) works except for
when the user attempts to terminate via "Task List" which causes "Program
not responding"...press "Cancel" and no issues, press "End now" and sure
enough it ends.

My question is; is there any method to prevent the "Application not
responding" message from appearing?

Current code:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
#Region " Windows Form Designer generated code "
Private bWasClick As Boolean
Private bAllowExit As Boolean
....
Public Const SC_CLOSE As System.Int32 = 61536
Public Const WM_SYSCOMMAND As System.Int32 = 274
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then
Me.bWasClick = True
If Me.CheckBox1.Checked Then
Return
End If
End If
MyBase.WndProc(m)
End Sub

....

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged
bAllowExit = DirectCast(sender, CheckBox).Checked()
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Me.bWasClick Then
'...
Else
'...
End If
e.Cancel = bAllowExit
End Sub

Visual Studio 1.1

Thanks for any assistance and for taking the time to read this question!
Kevin
Nov 21 '05 #1
2 3509
Kevin,

When you simple use the e.cancel in the window closing event is it much
easier

(It is nice to show a messagebox before you set this to true) otherwise it
can be called a kind of bug.

Cor
Nov 21 '05 #2
I left the messagebox out for clarity...at this point it ask to proceede or
abort rather then be rude to simply say no.

"Cor Ligthert" <no************@planet.nl> wrote in message
news:uY**************@tk2msftngp13.phx.gbl...
Kevin,

When you simple use the e.cancel in the window closing event is it much
easier

(It is nice to show a messagebox before you set this to true) otherwise it
can be called a kind of bug.

Cor

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kishor kotecha | last post by:
Hi, I have created a .net app. all works fine. but, i want to prevent closure (kill) of this app when the user of the machine does a 'log off' of windows/xp. currently what is happening...
2
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window catches its Closing event and cancels it if the...
22
by: alecjames1 | last post by:
I have a form which the user must complete before closing. I have disabled the window x button and use my own exit button. When selected it checks to see if the user has completed the entries...
7
by: alan | last post by:
Hello, When the user try the close the application (click the top right side button "X"), I would like to do a checking first. If the checking return false, prevent the application terminate....
7
by: Nikki | last post by:
Hi, Can anybody help me, i want to prevent windows to close my winform of ..NET application, when user presses Alt+F4
4
by: Daniel Walzenbach | last post by:
Hi, does anybody know the JavaScript the guys at Microsoft used in MS CRM to prevent people from closing a browser window and asking them (on the client) what they really want to do? If you...
9
by: Daniel Walzenbach | last post by:
Hi I am faced with the following problem: I have a page (let’s call this page page1.aspx) containing some TextBoxes and a hyperlink which opens another page (let’s call this page page2.aspx)...
2
by: Strahimir Antoljak | last post by:
Is it possible to prevent terminate the application (and how). I am aware of preventing the closing application, but here I mean on more violent cases when user tries to kill (terminate) the...
6
by: Velvet | last post by:
I am developing for a kiosk system. IE is loaded on this sytem and we want to make sure that there is a browser open to our website location at all times. So when the user closes the browser we...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.