By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,955 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,955 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.