473,699 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lock application when idle

4 New Member
Hi,

I need to lock my application if it has been idle for 15 minutes. This is a windows application in c#. I have put a timer in the main form and implemented the IMessageFilter interface. In the PreFilterMessag e method, I check for the key down and mouse move and mouse down messages. I am able to detect the inactivity if this application is not the active window.

I problem is I can't detect the idle time when the application is the active window, that is, I just leave the application in the foreground and do not do anything at all.

Can anyone help? Thanks.
Sep 17 '07 #1
5 2241
Plater
7,872 Recognized Expert Expert
if your application is the active application.... just use it's natural keydown/mousemove events.

Although, if you were correctly watching the keyboard/mouse events then it wouldn't matter what application had the focus as you would get the message from all of them.

See (Global Hooks):
http://www.codeproject.com/csharp/globalhook.asp
Sep 17 '07 #2
hmy
4 New Member
Thanks for the reply.

Let me elaborate more. This application is using .NET Framework 2.0, Smart Client Software Factory. My message filter is listening to the key and mouse events as below:

public bool PreFilterMessag e(ref Message m)
{
switch (m.Msg)
{
// movements to monitor
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_LBUTTONDBLCL K:
case WM_RBUTTONDBLCL K:
case WM_MBUTTONDBLCL K:
case WM_MOUSEWHEEL:
case WM_XBUTTONDOWN:
dtLastActivity = DateTime.Now;
break;
}
// we're not handling them, just monitoring so return false
return false;
}

Now if my mouse is anywhere on the view but "idle", the inactivity will not be detected. In other scenarios (app in background or minimized), it works perfectly. I tried writing the messages that were received and it looked like WM_MOUSEMOVE is still received even if there is no activity. Any ideas why?
Sep 18 '07 #3
Plater
7,872 Recognized Expert Expert
Well I'm not sure why, but you could try keeping track of a bit more "state" for that message.
Like everytime a mouse move message comes in, if the (X,Y) are not different then the saved (x,y) then ignore it. If they ARE different, update your saved (x,y) with those new values AND update your time of last activity object.
See if that helps?
Sep 18 '07 #4
Nivitha
3 New Member
Hi,
I am trying to do something very similar to the code you have posted.




Thanks for the reply.

Let me elaborate more. This application is using .NET Framework 2.0, Smart Client Software Factory. My message filter is listening to the key and mouse events as below:

public bool PreFilterMessag e(ref Message m)
{
switch (m.Msg)
{
// movements to monitor
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_LBUTTONDBLCL K:
case WM_RBUTTONDBLCL K:
case WM_MBUTTONDBLCL K:
case WM_MOUSEWHEEL:
case WM_XBUTTONDOWN:
dtLastActivity = DateTime.Now;
break;
}
// we're not handling them, just monitoring so return false
return false;
}

Now if my mouse is anywhere on the view but "idle", the inactivity will not be detected. In other scenarios (app in background or minimized), it works perfectly. I tried writing the messages that were received and it looked like WM_MOUSEMOVE is still received even if there is no activity. Any ideas why?
Jan 23 '08 #5
Nivitha
3 New Member
Hi,
I am also trying to do something similar to the code you have posted.
I got that sample from the following link:
http://www.thescripts.com/forum/thread256888.html
I am trying to put a breakpoint in the PreFilterMessag e(..) function but
not even once this function was called.
Can you please help me in this?
I have done the exact code as posted in the above link. Please let me know if any additional code/settings is needed.

Regards

Thanks for the reply.

Let me elaborate more. This application is using .NET Framework 2.0, Smart Client Software Factory. My message filter is listening to the key and mouse events as below:

public bool PreFilterMessag e(ref Message m)
{
switch (m.Msg)
{
// movements to monitor
case WM_KEYDOWN:
case WM_KEYUP:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_MOUSEMOVE:
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_LBUTTONDBLCL K:
case WM_RBUTTONDBLCL K:
case WM_MBUTTONDBLCL K:
case WM_MOUSEWHEEL:
case WM_XBUTTONDOWN:
dtLastActivity = DateTime.Now;
break;
}
// we're not handling them, just monitoring so return false
return false;
}

Now if my mouse is anywhere on the view but "idle", the inactivity will not be detected. In other scenarios (app in background or minimized), it works perfectly. I tried writing the messages that were received and it looked like WM_MOUSEMOVE is still received even if there is no activity. Any ideas why?
Jan 23 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
17793
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico Mariani, performance architect for the Microsoft® .NET runtime and longtime Microsoft developer, mentioned to Dr. GUI in an e-mail conversation recently that a fairly common practice (and one that's, unfortunately, described in some of our...
19
46654
by: Frank Rizzo | last post by:
I want to log the user out when there has been a period of inactivity in the application. The key here is inactivity of the application, not the system. I know that you can retrieve the inactivity of the system via GetLastInputInfo. That's not what I want - I want inactivity of the application. Thanks.
5
3124
by: Frank Rizzo | last post by:
Hello, I have a dozen 3rd party controls on my form. I am trying to detect when the application is idle. But even after the mouse and the keyboard are no longer moving, something is still triggering the Application.Idle event. There are no Timers on the form (i removed them all after realizing that WM_TIMER message will cause the event to fire). Anyway, how can I figure out which control is triggering the application_idle event? ...
4
1385
by: Rick Strahl [MVP] | last post by:
Hi all, I have an ASP.Net application that's online that's 'locking up' from time to time. It doesn't completely lock up but all of a sudden it appears to be stuck for about 20-30 seconds, before it catches and fires back up... The app doesn't restart itself (I'm logging this stuff) - it just starts working again. If there are multiple requests at that time they all are slow. They all go through, just at a glacial speed. I've checked...
20
4479
by: J-T | last post by:
We are working on an asp.net application which is a 3-tier application.I was aksed to create a component which monitors a folder and gets the file and pass them to a class library in our business logic layer(so far so good and easy).I initialize my class which is using a FileSystemWatcher in my Global.asax and everything works fine.I have found FileSystemWatcher class not very reliable and sometimes it behavies unexpectedly.I'm afriad that...
2
1653
by: henk | last post by:
I have a hard time to get the idle time only from my application. (a relogin box should appear after eg 1 min, when a user switch to word and start typing for 10min, the re-login should not appear. It should appear if my vb appication is active and there was no userinput for about 1 min. Found a example at http://www.vbmysql.com/samplecode/idle-time.html wich works fine, but it's "system wide". I tried something with me.windowstate but...
5
2507
by: Chakravarti Mukesh | last post by:
Hi, I want to get an event if someone locks her/his computer so that I could do some finalizations before actually locking the system. For example how can I ensure that an user close a particular application before locking her/his PC. Thanks Mukesh
2
5861
by: shenanwei | last post by:
DB2 V8.2 on AIX, type II index is created. I see this from deadlock event monitor. 5) Deadlocked Connection ... Participant no.: 2 Lock wait start time: 09/18/2006 23:04:09.911774 ...... Deadlocked Statement: Type : Dynamic Operation: Execute
0
11698
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to java.sql.SQLException: Deadlock found when trying to get lock; Try restarting transaction message from server: "Lock wait timeout exceeded; try restarting transaction"; We get such errors generally on inserts or updates while applying a
0
8612
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7743
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4373
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.