473,748 Members | 5,242 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tell if idle?

how can i tell if my system has gone idle? then how can i execute a command
accordingly? thnks
Nov 21 '05 #1
7 1990
"iwdu15" <iw****@discuss ions.microsoft. com> wrote in message
news:94******** *************** ***********@mic rosoft.com...
how can i tell if my system has gone idle? then how can i execute a
command
accordingly? thnks


Hi,

You can use class i wrote for my project:

--
Imports System.Timers
Imports System.Runtime. InteropServices

Public Class IdleWatcher
Implements IDisposable

<StructLayout(L ayoutKind.Seque ntial)> _
Public Structure LASTINPUTINFO
Public cbSize As Integer
Public dwTime As Integer
End Structure

<DllImport("use r32.dll", SetLastError:=T rue)> _
Public Shared Function GetLastInputInf o(ByRef lii As LASTINPUTINFO) As
Boolean
End Function

Private Const DEFAULT_CHECK_I NTERVAL As Integer = 500

Private _checkinterval As Integer
Private _maxidletime As Integer
Private WithEvents _timer As Timer = Nothing

Public Event Idle(ByVal sender As Object, ByVal e As EventArgs)

Sub New()
Me.New(DEFAULT_ CHECK_INTERVAL)
End Sub

Sub New(ByVal checkinterval As Integer)
_checkinterval = checkinterval
End Sub

Public Sub Dispose() Implements System.IDisposa ble.Dispose
[Stop]()
End Sub

Public Sub Start(ByVal maxidletime As Integer)
_maxidletime = maxidletime * 1000
_timer = New Timer(_checkint erval)
_timer.Start()
End Sub

Public Sub [Stop]()
If Not _timer Is Nothing Then
_timer.Stop()
_timer.Dispose( )
_timer = Nothing
End If
End Sub

Private Sub _timer_Elapsed( ByVal sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles _timer.Elapsed
Dim lii As New LASTINPUTINFO
lii.cbSize = Marshal.SizeOf( lii)

If GetLastInputInf o(lii) Then
Dim intIdle As Integer = System.Environm ent.TickCount -
lii.dwTime
If intIdle >= _maxidletime Then
_timer.Stop()
_timer = Nothing
RaiseEvent Idle(Me, New EventArgs)
End If
Else
Debug.WriteLine ("IdleWatche r Win32 ERROR: " +
Marshal.GetLast Win32Error().To String())
End If

lii = Nothing
End Sub

End Class
--

i hope this is what you are looking for

Regards,
Josip Habjan
URL: http://www.habjansoftware.com

Nov 21 '05 #2
"iwdu15" <iw****@discuss ions.microsoft. com> schrieb
how can i tell if my system has gone idle? then how can i execute a
command accordingly? thnks

Handle System.Windows. Forms.Applicati on.Idle. It's shared. This is related
to you own app. Or I'd better say, it's related to the current thread. It is
raised when all messages have been processed.

For the whole system it's a little bit more complicated. Idle is not really
idle because as soon as you're running whenever it's idle, it's not idle
anymore... It's better to say to execute something with the lowest priority
possible. Imagine there are two threads running, and both are set to "run
only if idle". What should they do? Which one should wait for the other to
finish?

Actually you have to set the _base priority_ of a thread. This is a
combination of the priority class of the process and the priority level of
the thread. Using the Framwork classes, you can set a thread's priority
level to System.Threadin g.ThreadPriorit y.Lowest. To set the process'
priority class, call System.Diagnost ics.Process.Get CurrentProcess and set
it's PriorityClass property to ProcessPriority Class.Idle. Please note that
this affects the whole process.

The final base priority is described here (table at the bottom):
http://msdn.microsoft.com/library/en...priorities.asp
As you see, there's also a THREAD_PRIORITY _IDLE priority for threads. This
is no available in the Thread class. However, there's a
System.Diagnost ics.ProcessThre ad.PriorityLeve l property. Unfortunatelly, I
haven't figured out how to find the corresponding ProcessThread object to a
Thread object to be able to set it to Idle. This shouldn't matter too much
because setting the thread's priority to Lowest is usually sufficient.
Setting it to Idle merely reduces the probability of being executed. This
would result in a let-me-be-the-lowest-priority-thread race which wouldn't
lead to anything in the end.
Armin
Nov 21 '05 #3
"iwdu15" <iw****@discuss ions.microsoft. com> schrieb:
how can i tell if my system has gone idle? then how can i execute a
command
accordingly?


<URL:http://groups.google.d e/groups?selm=epR V2mErEHA.324%40 TK2MSFTNGP11.ph x.gbl>

HOWTO track a user's idle time
<URL:http://www.codeproject .com/dll/trackuseridle.a sp>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4
hi, sry if i wasnt specific enough, i have a program that runs defrag and
starts the defragging the system, but i dont kno how to tell when its done so
i was looking into when the system was idle. i want to shutdown the computer
once the defrag is done, so if anyone can help me on this thatd b great
Nov 21 '05 #5

Pay $50 for Diskkeeper Workstation. It does this and you save your time for
other projects.

Mike Ober.

"iwdu15" <iw****@discuss ions.microsoft. com> wrote in message
news:7F******** *************** ***********@mic rosoft.com...
hi, sry if i wasnt specific enough, i have a program that runs defrag and
starts the defragging the system, but i dont kno how to tell when its done so i was looking into when the system was idle. i want to shutdown the computer once the defrag is done, so if anyone can help me on this thatd b great


Nov 21 '05 #6
i was wondering if its possible, cause im a relativly new programmer, so i
dont have to save time for any projects, imn just programming this in my free
time to learn everything i can about the language, so if there is a way, id
like to kno but if there isnt il take a look into that software you told me
about
Nov 21 '05 #7

In that case, take a look at the MSDN section on the Task Scheduler
http://msdn.microsoft.com/library/de...start_page.asp.
You have to instruct the system to start your code when it's idle. There is
no system wide message alerting applications to the "System Idle" state.

Mike Ober.
"iwdu15" <iw****@discuss ions.microsoft. com> wrote in message
news:D1******** *************** ***********@mic rosoft.com...
i was wondering if its possible, cause im a relativly new programmer, so i
dont have to save time for any projects, imn just programming this in my free time to learn everything i can about the language, so if there is a way, id like to kno but if there isnt il take a look into that software you told me about


Nov 21 '05 #8

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

Similar topics

16
12926
by: Kerry Neilson | last post by:
For the past couple of months, Idle won't start when I invoke it. I am at a complete loss for why this is. When this happens, they python command line still starts, and python works fine otherwise. Most interesting to me is that a reboot won't fix the problem. But if I just try it again sometime later it will work. Anyone have any ideas? I'm running python 2.3 on windows 2000 professional.
1
5540
by: Moosebumps | last post by:
So say I am working on two separate .py files in IDLE that are part of the same program. Does anyone have problems where when you modify one file, and then run the other, the changes you made in the first aren't updated? I usually just close all the files, and restart IDLE, but this is a pain. Maybe because I always use right click -> edit with IDLE (on Windows). That starts up a separate Python Shell too, which I always close. MB
1
6728
by: dbrown2 | last post by:
I typically use IDLE for editing and debug. On Windows at least, IDLE and the standard turtle graphics module do not mix. I think both use Tkinter. For now I use IPython and Jedit when using the turtle module but it's not a great solution for me. Is there any known work-around to use turtle with IDLE? If not is there a planned fix for the problem. I find turtle is a convenient way to do simple graphics without having to install...
8
3773
by: Jonathan Polley | last post by:
I have one account on a WindowsXP machine that refuses to run IDLE (or any other python script that uses Tk). Other people can login to that PC and IDLE runs just fine, so it is not an installation issue. When the person who has the problem logs into another PC the problem follows them. Any ideas as to what might me wrong? This is the traceback from IDLE: C:\Python20\Tools\idle>..\..\python.exe idle.py Traceback (most recent call...
2
1350
by: Robert D. Young | last post by:
I've probably asked this before, but how can I tell within the program I'm running if the .py files was involved by "run module" in IDLE or by using the .py assoication with the python.exe program? I'd like to prevent running under certain circumstances, or pop-up warnings, or change character displays (some look different when run under IDLE). - Robert
19
46683
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
2140
by: Kevin Buchan | last post by:
How can I tell if the system is 'idle', or the screen saver is running, or the machine is locked? I am writing an application that could really benefit from knowing this information. During 'idle' time, I could do some of the slightly heavier processing; during the 'working' time, I would display the non-intrusive notifications that I don't want my customer to miss. I see that I can apparently set the thread priority of my background...
5
2795
by: Russ P. | last post by:
I've been programming in python for a few years using XEmacs on Solaris and Linux. I've been thinking about trying IDLE for a long time, but either it wasn't available on my system or I procrastinated. I finally have it available, and I gave it a try. I immediately encountered a basic problem for which I could not find a solution in the intro docs. I want to run a script in one directory that reads input from a file in another directory....
5
1824
by: dg.google.groups | last post by:
Hi all, Is there any standard way to tell if the user is running from a module or from an interactive shell like IDLE or IPython? The best I've come up with so far is for a function to look at getouterframes(currentframe()) (the filename in the frame record of the frame that called the function), and check if it exists or not with os.path.exists. IPython gives '(ipython console)' and IDLE gives 'pyshell#0' whereas running from a module...
0
8987
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9534
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
9366
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...
1
9316
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
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...
0
6073
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3303
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
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.