How to know the application is in use or not

J

Joby

Dear All,
I am Joby M.Chacko. In my appliaction i want to know whether my
application
is working or not. Context is AuotoLogOff. If the application is not
using for a particular time, the application has to exit. (C# Pocket
PC Apllication)
Thanking You.
Joby M.Chacko.
 
P

Paul G. Tobey [eMVP]

"working" is not very specific. I suppose that you could use the OpenNETCF
ApplicationEx class and, each time a message is received, reset an 'idle
counter'. If the idle counter reached some sort of time-out value, you
could then shut down the application or whatever. You'd have to tell us
what sort of events should prevent auto log off...

Paul T.
 
J

Joby

Dear Mr:paul G. Tobey,
Thanks for the replay.More specific - If our application is working
one side, the user started doing some other work on the other
application. He came back to our application and do some work.Then for
the next 10 minutes he do not do anything in our application. In that
case our application has to exit.
That means if our application is not using for a particular time, our
application should exit.
Thanks for your precious time.
Regards
Joby
 
P

Paul G. Tobey [eMVP]

This is a scenario that you *can* handle. Use the OpenNETCF ApplicationEx
object and trap the messages that constitute 'actions' in a message filter.
You don't want to process them, but you want to reset a timer every time an
action occurs. If the timer fires, the application has been inactive for
the idle period and you should do whatever you want. My suggestion would be
to use a timer. Here are a few code bits from a test I wrote for this:

The filter class:

public const int WM_KEYDOWN = 0x0100;

public const int VK_CONTROL = 0x11;

public const int WM_KEYUP = 0x0101;

public const int WM_CHAR = 0x0102;

public const int WM_DEADCHAR= 0x0103;

public const int WM_SYSKEYDOWN = 0x0104;

public const int WM_SYSKEYUP = 0x0105;

public const int WM_SYSCHAR = 0x0106;

public const int WM_SYSDEADCHAR = 0x0107;

public const int WM_LBUTTONDOWN = 0x0201;

public const int WM_LBUTTONUP = 0x0202;

public const int WM_LBUTTONDBLCLK = 0x0203;

public const int WM_RBUTTONDOWN = 0x0204;

public const int WM_RBUTTONUP = 0x0205;

public const int WM_RBUTTONDBLCLK = 0x0206;

public const int WM_MBUTTONDOWN = 0x0207;

public const int WM_MBUTTONUP = 0x0208;

public const int WM_MBUTTONDBLCLK = 0x0209;

protected Form1 mainForm;

// We need to store a copy of the main form so that

// we can access the timer. Start the timer

// immediately here.

public KeyFilter( Form1 f )

{

mainForm = f;

f.StartTimer();

}

// Before shutdown, turn the timer off. We're exiting

// anyway.

public void Dispose()

{

mainForm.StopTimer();

}



public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)

{

// Reset the idle timer, if any of the target

// events occur.

if ( ( m.Msg == WM_KEYDOWN ) || ( m.Msg == WM_KEYUP ) || ( m.Msg ==
WM_CHAR ) ||

( m.Msg == WM_SYSKEYDOWN ) || ( m.Msg == WM_SYSKEYUP ) || ( m.Msg ==
WM_SYSCHAR ) ||

( m.Msg == WM_LBUTTONDOWN ) || ( m.Msg == WM_LBUTTONUP ) || ( m.Msg ==
WM_LBUTTONDBLCLK ) ||

( m.Msg == WM_RBUTTONDOWN ) || ( m.Msg == WM_RBUTTONUP ) || ( m.Msg ==
WM_RBUTTONDBLCLK ) )

{

mainForm.ResetTimer();

}

return false;

}



And some code from the main form:



protected Timer idleTimer = null;

public void StartTimer()

{

// Start the idle timer. The time-out is 15

// seconds.

idleTimer = new Timer();

idleTimer.Interval = 15000;

idleTimer.Tick += new EventHandler(idleTimer_Tick);

idleTimer.Enabled = true;

}

public void StopTimer()

{

// Stop/dispose the idle timer.

if ( idleTimer != null )

{

idleTimer.Dispose();

idleTimer = null;

}

}

public void ResetTimer()

{

// Restart the time-out for the timer.

idleTimer.Enabled = false;

idleTimer.Enabled = true; // Restart the timer?

}

public void idleTimer_Tick( object o, System.EventArgs e )

{

// Time-out. Arrange to exit the application.

this.StopTimer();

this.Close();

// ????

}



Paul T.



Joby said:
Dear Mr:paul G. Tobey,
Thanks for the replay.More specific - If our application is working
one side, the user started doing some other work on the other
application. He came back to our application and do some work.Then for
the next 10 minutes he do not do anything in our application. In that
case our application has to exit.
That means if our application is not using for a particular time, our
application should exit.
Thanks for your precious time.
Regards
Joby

"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> wrote in
message news: said:
"working" is not very specific. I suppose that you could use the OpenNETCF
ApplicationEx class and, each time a message is received, reset an 'idle
counter'. If the idle counter reached some sort of time-out value, you
could then shut down the application or whatever. You'd have to tell us
what sort of events should prevent auto log off...

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top