473,394 Members | 1,739 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,394 software developers and data experts.

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 2945
Hi,

I would try to use
system.Windows.Forms.Form.ActiveForm.MousePosition


"Jeff S" <A@B.COM> wrote in message
news:eU**************@TK2MSFTNGP09.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***@paradigmitz.net.au> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl...
Hi,

I would try to use
system.Windows.Forms.Form.ActiveForm.MousePosition


"Jeff S" <A@B.COM> wrote in message
news:eU**************@TK2MSFTNGP09.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.KeyPreview = 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*************@TK2MSFTNGP15.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***@paradigmitz.net.au> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl...
Hi,

I would try to use
system.Windows.Forms.Form.ActiveForm.MousePosition


"Jeff S" <A@B.COM> wrote in message
news:eU**************@TK2MSFTNGP09.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.AddMessageFilter.

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 GetLastInputInfo (min req Win2K)

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

--
HTH
Stoitcho Goutsev (100)
"Jared" <ja***@paradigmitz.net.au> wrote in message
news:uk**************@TK2MSFTNGP12.phx.gbl...
As for key events, MDIParent.KeyPreview = 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*************@TK2MSFTNGP15.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***@paradigmitz.net.au> wrote in message
news:em**************@TK2MSFTNGP09.phx.gbl...
Hi,

I would try to use
system.Windows.Forms.Form.ActiveForm.MousePosition


"Jeff S" <A@B.COM> wrote in message
news:eU**************@TK2MSFTNGP09.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
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...
1
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...
3
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...
20
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
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...
5
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...
8
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...
5
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...
22
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
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...

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.