C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

how get Other Application Idle Time in c#?


Posted Date: 04 Dec 2008      Posted By: MURUGESAN      Member Level: Silver     Points: 1   Responses: 2



i had created one Windows service, that service will invoke one Application
like notepad etc, how to get notepad Idle time in c#? very urcent





Responses

Author: Patel    04 Dec 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

The implemented solution calls functions inside the user32.dll and kernel32.dll files.

To do this, it is necessary:

To add a reference to the System.Runtime.InteropServices namespace.
To know the name and definition of the function to be called.
To create an extern function using C#.
To make any additional structure to be used in the called functions.

// Step 1
using System.Runtime.InteropServices;

// Steps 2 and 3
[DllImport("User32.dll")]
private static extern bool
GetLastInputInfo(ref LASTINPUTINFO plii);

//Step 4
internal struct LASTINPUTINFO
{
public uint cbSize;

public uint dwTime;
}
When I was trying to make things works, I found an issue with the LASTINPUTINFO structure. I solved the problem by creating a C# struct with the same members as the original function. Note that you need to know the mapping between a Windows data type and the .NET Framework data types. The following table is very useful:

BOOL Boolean variable (should be TRUE or FALSE).
BOOLEAN Boolean variable (should be TRUE or FALSE).
BYTE Byte (8 bits).
CALLBACK Calling convention for callback functions.
CHAR 8-bit Windows (ANSI) character.
COLORREF Red, green, blue (RGB) color value (32 bits).
CONST Variable whose value is to remain constant during execution.
DWORD 32-bit unsigned integer.
DWORD_PTR Unsigned long type for pointer precision. Use when casting a pointer to a long type to perform pointer arithmetic. (Also commonly used for general 32-bit parameters that have been extended to 64 bits in 64-bit Windows.)
INT 32-bit signed integer.
INT_PTR Signed integral type for pointer precision. Use when casting a pointer to an integer to perform pointer arithmetic.
INT32 32-bit signed integer.
INT64 64-bit signed integer.
LONG 32-bit signed integer.
LONG_PTR Signed long type for pointer precision. Use when casting a pointer to a long to perform pointer arithmetic.
LONG32 32-bit signed integer.
LONG64 64-bit signed integer.
LONGLONG 64-bit signed integer.
LPARAM Message parameter.
LPBOOL Pointer to a BOOL.
LPBYTE Pointer to a BYTE.

When using a struct as a parameter, you have to initialize it before it is passed to the function:

LASTINPUTINFO lastInPut = new LASTINPUTINFO();
lastInPut.cbSize = (uint)
System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);



Author: Patel    04 Dec 2008Member Level: SilverRating: 2 out of 52 out of 5     Points: 1

visit Below Link
http://www.geekpedia.com/tutorial210_Retrieving-the-Operating-System-Idle-Time-Uptime-and-Last-Input-Time.html



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Spring.NET
Previous : create an automated installation tool
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use