473,545 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Auto Shut-Down to Windows Forms App After N Minutes of Inactivity

I'm creating a new Windows Forms MDI application...

How can I add cause the application to shut itself down after a period of
[no user activity]?

I did this in an old COM/VB6 application and I had to have code behind
practically all visible UI controls (triggered on the Mouse_Move event) that
reset a global variable monitored by a timer. If the global value
incremented past a certain point, then a Timer event procedure would cause a
dialog to appear. If the user failed to respond to the dialog after 10
seconds, then the app would shut down.

Does .NET give us an easier way to accomplish the same? I don't want to have
to detect the mouse_move event of practically every UI control and have a
timer running in the background the whole time, if possible.

Thanks!
Feb 21 '06 #1
5 2955
Hi,

I would try to use
system.Windows. Forms.Form.Acti veForm.MousePos ition


"Jeff S" <A@B.COM> wrote in message
news:eU******** ******@TK2MSFTN GP09.phx.gbl...
I'm creating a new Windows Forms MDI application...

How can I add cause the application to shut itself down after a period of
[no user activity]?

I did this in an old COM/VB6 application and I had to have code behind
practically all visible UI controls (triggered on the Mouse_Move event)
that reset a global variable monitored by a timer. If the global value
incremented past a certain point, then a Timer event procedure would cause
a dialog to appear. If the user failed to respond to the dialog after 10
seconds, then the app would shut down.

Does .NET give us an easier way to accomplish the same? I don't want to
have to detect the mouse_move event of practically every UI control and
have a timer running in the background the whole time, if possible.

Thanks!

Feb 21 '06 #2
Hummm, MousePosition is a property. How would I use that to determine if
there has been any user activity? Are you suggesting that I periodically
check the mouse coordinates? Not sure that would work for all scenarios -
like if the user is simply typing and not moving the mouse, or if they have
multiple MDI child windows open, then I'd have to have complicated logic
that determines which is the active one... But it might be part of a
solution...

-Jeff
"Jared" <ja***@paradigm itz.net.au> wrote in message
news:em******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I would try to use
system.Windows. Forms.Form.Acti veForm.MousePos ition


"Jeff S" <A@B.COM> wrote in message
news:eU******** ******@TK2MSFTN GP09.phx.gbl...
I'm creating a new Windows Forms MDI application...

How can I add cause the application to shut itself down after a period of
[no user activity]?

I did this in an old COM/VB6 application and I had to have code behind
practically all visible UI controls (triggered on the Mouse_Move event)
that reset a global variable monitored by a timer. If the global value
incremented past a certain point, then a Timer event procedure would
cause a dialog to appear. If the user failed to respond to the dialog
after 10 seconds, then the app would shut down.

Does .NET give us an easier way to accomplish the same? I don't want to
have to detect the mouse_move event of practically every UI control and
have a timer running in the background the whole time, if possible.

Thanks!


Feb 21 '06 #3
As for key events, MDIParent.KeyPr eview = true

Not sure if this would have to be done for all forms?

Yes, I was thinking of using a timer.
"Jeff S" <A@B.COM> wrote in message
news:uT******** *****@TK2MSFTNG P15.phx.gbl...
Hummm, MousePosition is a property. How would I use that to determine if
there has been any user activity? Are you suggesting that I periodically
check the mouse coordinates? Not sure that would work for all scenarios -
like if the user is simply typing and not moving the mouse, or if they
have multiple MDI child windows open, then I'd have to have complicated
logic that determines which is the active one... But it might be part of a
solution...

-Jeff
"Jared" <ja***@paradigm itz.net.au> wrote in message
news:em******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I would try to use
system.Windows. Forms.Form.Acti veForm.MousePos ition


"Jeff S" <A@B.COM> wrote in message
news:eU******** ******@TK2MSFTN GP09.phx.gbl...
I'm creating a new Windows Forms MDI application...

How can I add cause the application to shut itself down after a period
of [no user activity]?

I did this in an old COM/VB6 application and I had to have code behind
practically all visible UI controls (triggered on the Mouse_Move event)
that reset a global variable monitored by a timer. If the global value
incremented past a certain point, then a Timer event procedure would
cause a dialog to appear. If the user failed to respond to the dialog
after 10 seconds, then the app would shut down.

Does .NET give us an easier way to accomplish the same? I don't want to
have to detect the mouse_move event of practically every UI control and
have a timer running in the background the whole time, if possible.

Thanks!



Feb 21 '06 #4
It sounds as though your task parallels the behavior of screen savers. Perhaps
you could investigate how those are implemented. There must be something they
use to watch activity of the mouse and keyboard.

Just a thought.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Feb 21 '06 #5
Jared,

First off mouse and key messages comes through the windows message loop. In
this case you can use message filter to handle all mouse and keyboard
message globally for the whole application. Look at
Application.Add MessageFilter.

Secondly it depends on your definition on user inactivity. Is it just not
working wiht the application or is just not using that particular
application? In the latter case you can use message filters as I suggested
earlier in the former you have no managed solution. You should resort do
native API GetLastInputInf o (min req Win2K)

Third option is to use low level keyboard and mouse hookd which requirese
PInvoke again.

--
HTH
Stoitcho Goutsev (100)
"Jared" <ja***@paradigm itz.net.au> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...
As for key events, MDIParent.KeyPr eview = true

Not sure if this would have to be done for all forms?

Yes, I was thinking of using a timer.
"Jeff S" <A@B.COM> wrote in message
news:uT******** *****@TK2MSFTNG P15.phx.gbl...
Hummm, MousePosition is a property. How would I use that to determine if
there has been any user activity? Are you suggesting that I periodically
check the mouse coordinates? Not sure that would work for all scenarios -
like if the user is simply typing and not moving the mouse, or if they
have multiple MDI child windows open, then I'd have to have complicated
logic that determines which is the active one... But it might be part of
a solution...

-Jeff
"Jared" <ja***@paradigm itz.net.au> wrote in message
news:em******** ******@TK2MSFTN GP09.phx.gbl...
Hi,

I would try to use
system.Windows. Forms.Form.Acti veForm.MousePos ition


"Jeff S" <A@B.COM> wrote in message
news:eU******** ******@TK2MSFTN GP09.phx.gbl...
I'm creating a new Windows Forms MDI application...

How can I add cause the application to shut itself down after a period
of [no user activity]?

I did this in an old COM/VB6 application and I had to have code behind
practically all visible UI controls (triggered on the Mouse_Move event)
that reset a global variable monitored by a timer. If the global value
incremented past a certain point, then a Timer event procedure would
cause a dialog to appear. If the user failed to respond to the dialog
after 10 seconds, then the app would shut down.

Does .NET give us an easier way to accomplish the same? I don't want to
have to detect the mouse_move event of practically every UI control and
have a timer running in the background the whole time, if possible.

Thanks!



Feb 21 '06 #6

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

Similar topics

2
2592
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code that follows C++ RAII pattern. Of course Python objects are not statics like in C++, but in C++ the auto_ptr class is used for enforcing this...
1
13947
by: Glabbeek | last post by:
I'm changing the layout of my site. Instead of using tables, I will use DIVs. It's working fine, except for 1 thing: In IE6 some DIVs are not the correct width. Mozilla and Opera are showing the page the way I want. Does anybody know a solution for this? First of all, the code I am using: CSS ------- body {
3
1314
by: Adel | last post by:
Hello. Is the statement below proved by the ANSI C standard? "It is undesirable to use explicitly sized variables in functions as auto variables or parameters. The values will always be stored as the processor native word size, and extra code will be generated by the compiler to mask off bits that are not significant in the result." Adel
20
2836
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
5053
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which...
5
5032
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the CurrentUICulture to what's specified in the querystring. Since I want to allow UICulture auto detecting, I add UICulture = "auto" to page directive on...
8
1905
by: ApexData | last post by:
Hello I have just completed the development of a turn-key Access2k application. I am using MS Access 2000k application, not the RunTime. I have compiled it, split it (FE & BE), set all the StartUp Options to Off, and created the FE MDE. My problem is that the MS Access (File->Edit->Insert->Records->Window->Help) Menu still appears at the...
5
3251
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if I change 'auto' to 0 for left and right margin values; I have to leave those at 'auto'.. so I would like to know what exactly means 'auto' -- what...
22
3038
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly like that: int main(char argc, char *argv, char *env) { try { auto Exception mainException(1); mainException.setErrNo(42);
2
2560
by: kkramer | last post by:
I have a table in Access which is auto populating fields which I do not want to happen. If I list a number in a field, and then another number in the field below it, and then a third number, if those numbers happen to coincidentally follow a pattern (for example, 10322,10324,10326), the fields below are auto populating to follow the same pattern....
0
7470
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7405
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7659
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7428
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5334
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4949
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3455
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.