PC Review


Reply
Thread Tools Rate Thread

Application Idle

 
 
MDB
Guest
Posts: n/a
 
      19th Aug 2004
Hello All, I am trying to create a timer using the OpenNetCf to find out
when the application is on idle and have been having some problems. I have
found some example code using VB
(http://wiki.opennetcf.org/ow.asp?AppIdleTimer) however I am using C#. Here
is what my code looks like. Does anyone see what I am doing wrong?
using IMessageFilter = MyApp.AppIdleTimer;

CLASS:

public class AppIdleTimer
{

public delegate void TimeoutDelegate();
public event TimeoutDelegate AppTimeOut;
private System.Windows.Forms.Timer m_timer = new
System.Windows.Forms.Timer();

public void New(int TimeoutInterval)
{
m_timer.Tick +=new EventHandler(m_timer_Tick);
m_timer.Interval = TimeoutInterval;
m_timer.Enabled = true;
}

private void m_timer_Tick(object sender,EventArgs e)
{
AppTimeOut();
Application.DoEvents();
}

private void Dispose()
{
m_timer.Enabled = false;
}

OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
public void PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)
{
switch(m.Msg.ToString())
{
case "&H200":
case "&H201":
case "&H202":
case "&H203":
case "&H204":
case "&H205":
case "&H206":
case "&H207":
case "&H208":
case "&H209":
case "&H100":
case "&H101":
case "&H102":
case "&H103":
case "&H104":
case "&H105":
case "&H106":
case "&H107":
case "&H108":
{
m_timer.Enabled = false;
m_timer.Enabled = true;
break;
}
}
}
}


INSIDE THE MAIN

AppIdleTimer appIdle = new AppIdleTimer();
appIdle.New(10000);
appIdle.AppTimeOut += new
MyApp.AppIdleTimer.TimeoutDelegate(appIdle_AppTimeOut);

*** Getting This Error
***The best overloaded method match for
'OpenNETCF.Windows.Forms.ApplicationEx.AddMessageFilter(OpenNETCF.Windows.Fo
rms.IMessageFilter)' has some invalid arguments
***Here

ApplicationEx.AddMessageFilter(appIdle);
ApplicationEx.Run();




private void appIdle_AppTimeOut()
{
MessageBox.Show("TimeOut");
}


 
Reply With Quote
 
 
 
 
Daniel Bass
Guest
Posts: n/a
 
      20th Aug 2004
Hey there,

I've done something similar for a user logging in and out of a device, below
is the code I used:

//------------------------------------------------------------------------------------------
[MESSAGEFILTER.CS]

using System;
using System.Windows.Forms;
using OpenNETCF.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace MyApp
{
/// <summary>
/// Summary description for MessageFilter.
/// </summary>
public class MessageFilter : IMessageFilter
{
// resst the time out for user log-ins
public bool PreFilterMessage(ref Message m)
{
if ( m.Msg != 275 ) // message of time out event
AppData.m_timeOfLastAction = DateTime.Now;

return false;
}
}
}


//------------------------------------------------------------------------------------------
[APPDATA.CS]

using System;

namespace MyApp
{
/// <summary>
/// Summary description for AppData.
/// </summary>
public class AppData
{

public static DateTime m_timeOfLastAction = DateTime.Now;

//
// other public global data and constants here

}
}

//------------------------------------------------------------------------------------------
[FORM1.CS - snippet]
static void Main()
{
try
{

MessageFilter msgFlter = new MessageFilter();
ApplicationEx.AddMessageFilter ( msgFlter );
ApplicationEx.Run(new FormMain());
}
catch ( Exception ex )
{
MessageBox.Show ( "Unhandled Exception occurred... " +
ex.Message, "Error" );
}
}

//
// other stuff
//

private System.Windows.Forms.Timer timerSessionExpires;

TimeSpan timeExpiry = TimeSpan.FromMinutes ( 30.0 );

private void timerSessionExpires_Tick(object sender,
System.EventArgs e)
{
if ( !AppData.m_bLoggedIn ) // flag in AppData
{
AppData.m_timeOfLastAction = DateTime.Now;
return;
}

if ( DateTime.Now.Subtract ( timeExpiry ) >
AppData.m_timeOfLastAction )
{
//
// current session has expired, user needs to log in again

AppData.LogOut(); // implemented in AppData

AppData.m_timeOfLastAction = DateTime.Now;
}

}

//
// other stuff
//

//------------------------------------------------------------------------------------------


The first main difference in you version and mine is your PreFilterMessage
is inclusive, where as mine is exclusive, since I know the event message
number of the timer that's checking my last action, I exclude it.
The second is my object for message filtering is minimul in content and I
leave the working out time bits to the main form.

Hope that helps.

Daniel.



"MDB" <nospam> wrote in message
news:(E-Mail Removed)...
> Hello All, I am trying to create a timer using the OpenNetCf to find out
> when the application is on idle and have been having some problems. I
> have
> found some example code using VB
> (http://wiki.opennetcf.org/ow.asp?AppIdleTimer) however I am using C#.
> Here
> is what my code looks like. Does anyone see what I am doing wrong?
> using IMessageFilter = MyApp.AppIdleTimer;
>
> CLASS:
>
> public class AppIdleTimer
> {
>
> public delegate void TimeoutDelegate();
> public event TimeoutDelegate AppTimeOut;
> private System.Windows.Forms.Timer m_timer = new
> System.Windows.Forms.Timer();
>
> public void New(int TimeoutInterval)
> {
> m_timer.Tick +=new EventHandler(m_timer_Tick);
> m_timer.Interval = TimeoutInterval;
> m_timer.Enabled = true;
> }
>
> private void m_timer_Tick(object sender,EventArgs e)
> {
> AppTimeOut();
> Application.DoEvents();
> }
>
> private void Dispose()
> {
> m_timer.Enabled = false;
> }
>
> OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
> public void PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)
> {
> switch(m.Msg.ToString())
> {
> case "&H200":
> case "&H201":
> case "&H202":
> case "&H203":
> case "&H204":
> case "&H205":
> case "&H206":
> case "&H207":
> case "&H208":
> case "&H209":
> case "&H100":
> case "&H101":
> case "&H102":
> case "&H103":
> case "&H104":
> case "&H105":
> case "&H106":
> case "&H107":
> case "&H108":
> {
> m_timer.Enabled = false;
> m_timer.Enabled = true;
> break;
> }
> }
> }
> }
>
>
> INSIDE THE MAIN
>
> AppIdleTimer appIdle = new AppIdleTimer();
> appIdle.New(10000);
> appIdle.AppTimeOut += new
> MyApp.AppIdleTimer.TimeoutDelegate(appIdle_AppTimeOut);
>
> *** Getting This Error
> ***The best overloaded method match for
> 'OpenNETCF.Windows.Forms.ApplicationEx.AddMessageFilter(OpenNETCF.Windows.Fo
> rms.IMessageFilter)' has some invalid arguments
> ***Here
>
> ApplicationEx.AddMessageFilter(appIdle);
> ApplicationEx.Run();
>
>
>
>
> private void appIdle_AppTimeOut()
> {
> MessageBox.Show("TimeOut");
> }
>
>



 
Reply With Quote
 
MDB
Guest
Posts: n/a
 
      23rd Aug 2004
Thanks, I will try it out.


"Daniel Bass" <DanielBass TAKE at OUT CAPS WORDS Postmaster.co.uk> wrote in
message news:(E-Mail Removed)...
> Hey there,
>
> I've done something similar for a user logging in and out of a device,

below
> is the code I used:
>
>

//--------------------------------------------------------------------------
----------------
> [MESSAGEFILTER.CS]
>
> using System;
> using System.Windows.Forms;
> using OpenNETCF.Windows.Forms;
> using Microsoft.WindowsCE.Forms;
>
> namespace MyApp
> {
> /// <summary>
> /// Summary description for MessageFilter.
> /// </summary>
> public class MessageFilter : IMessageFilter
> {
> // resst the time out for user log-ins
> public bool PreFilterMessage(ref Message m)
> {
> if ( m.Msg != 275 ) // message of time out event
> AppData.m_timeOfLastAction = DateTime.Now;
>
> return false;
> }
> }
> }
>
>
>

//--------------------------------------------------------------------------
----------------
> [APPDATA.CS]
>
> using System;
>
> namespace MyApp
> {
> /// <summary>
> /// Summary description for AppData.
> /// </summary>
> public class AppData
> {
>
> public static DateTime m_timeOfLastAction = DateTime.Now;
>
> //
> // other public global data and constants here
>
> }
> }
>
>

//--------------------------------------------------------------------------
----------------
> [FORM1.CS - snippet]
> static void Main()
> {
> try
> {
>
> MessageFilter msgFlter = new MessageFilter();
> ApplicationEx.AddMessageFilter ( msgFlter );
> ApplicationEx.Run(new FormMain());
> }
> catch ( Exception ex )
> {
> MessageBox.Show ( "Unhandled Exception occurred... " +
> ex.Message, "Error" );
> }
> }
>
> //
> // other stuff
> //
>
> private System.Windows.Forms.Timer timerSessionExpires;
>
> TimeSpan timeExpiry = TimeSpan.FromMinutes ( 30.0 );
>
> private void timerSessionExpires_Tick(object sender,
> System.EventArgs e)
> {
> if ( !AppData.m_bLoggedIn ) // flag in AppData
> {
> AppData.m_timeOfLastAction = DateTime.Now;
> return;
> }
>
> if ( DateTime.Now.Subtract ( timeExpiry ) >
> AppData.m_timeOfLastAction )
> {
> //
> // current session has expired, user needs to log in again
>
> AppData.LogOut(); // implemented in AppData
>
> AppData.m_timeOfLastAction = DateTime.Now;
> }
>
> }
>
> //
> // other stuff
> //
>
>

//--------------------------------------------------------------------------
----------------
>
>
> The first main difference in you version and mine is your PreFilterMessage
> is inclusive, where as mine is exclusive, since I know the event message
> number of the timer that's checking my last action, I exclude it.
> The second is my object for message filtering is minimul in content and I
> leave the working out time bits to the main form.
>
> Hope that helps.
>
> Daniel.
>
>
>
> "MDB" <nospam> wrote in message
> news:(E-Mail Removed)...
> > Hello All, I am trying to create a timer using the OpenNetCf to find

out
> > when the application is on idle and have been having some problems. I
> > have
> > found some example code using VB
> > (http://wiki.opennetcf.org/ow.asp?AppIdleTimer) however I am using C#.
> > Here
> > is what my code looks like. Does anyone see what I am doing wrong?
> > using IMessageFilter = MyApp.AppIdleTimer;
> >
> > CLASS:
> >
> > public class AppIdleTimer
> > {
> >
> > public delegate void TimeoutDelegate();
> > public event TimeoutDelegate AppTimeOut;
> > private System.Windows.Forms.Timer m_timer = new
> > System.Windows.Forms.Timer();
> >
> > public void New(int TimeoutInterval)
> > {
> > m_timer.Tick +=new EventHandler(m_timer_Tick);
> > m_timer.Interval = TimeoutInterval;
> > m_timer.Enabled = true;
> > }
> >
> > private void m_timer_Tick(object sender,EventArgs e)
> > {
> > AppTimeOut();
> > Application.DoEvents();
> > }
> >
> > private void Dispose()
> > {
> > m_timer.Enabled = false;
> > }
> >
> > OpenNETCF.Windows.Forms.IMessageFilter.PreFilterMessage
> > public void PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message m)
> > {
> > switch(m.Msg.ToString())
> > {
> > case "&H200":
> > case "&H201":
> > case "&H202":
> > case "&H203":
> > case "&H204":
> > case "&H205":
> > case "&H206":
> > case "&H207":
> > case "&H208":
> > case "&H209":
> > case "&H100":
> > case "&H101":
> > case "&H102":
> > case "&H103":
> > case "&H104":
> > case "&H105":
> > case "&H106":
> > case "&H107":
> > case "&H108":
> > {
> > m_timer.Enabled = false;
> > m_timer.Enabled = true;
> > break;
> > }
> > }
> > }
> > }
> >
> >
> > INSIDE THE MAIN
> >
> > AppIdleTimer appIdle = new AppIdleTimer();
> > appIdle.New(10000);
> > appIdle.AppTimeOut += new
> > MyApp.AppIdleTimer.TimeoutDelegate(appIdle_AppTimeOut);
> >
> > *** Getting This Error
> > ***The best overloaded method match for
> >

'OpenNETCF.Windows.Forms.ApplicationEx.AddMessageFilter(OpenNETCF.Windows.Fo
> > rms.IMessageFilter)' has some invalid arguments
> > ***Here
> >
> > ApplicationEx.AddMessageFilter(appIdle);
> > ApplicationEx.Run();
> >
> >
> >
> >
> > private void appIdle_AppTimeOut()
> > {
> > MessageBox.Show("TimeOut");
> > }
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Application Idle Time Visu Microsoft VB .NET 1 22nd Nov 2007 04:13 PM
Application.Idle not called when application does not have focus dcolak@gmail.com Microsoft Dot NET Framework Forms 1 1st Nov 2006 06:00 PM
Application.Idle Rob Microsoft VB .NET 1 2nd Oct 2005 12:42 AM
application idle time Dayne Microsoft VB .NET 2 9th Oct 2004 11:24 AM
Application.idle sbcglobal Microsoft VB .NET 2 8th Jan 2004 07:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:36 PM.