检测用户 Activity windows phone 8
Detect User Activity windows phone 8
我启动 DispatcherTimer 的代码。
我只需要检测任何类型的用户 Ineraction 以重新启动 DispatcherTimer?
public partial class MainMenu : PhoneApplicationPage
{
public MainMenu()
{
InitializeComponent();
startTimer();
}
private DispatcherTimer dispatcherTimer;
private void startTimer()
{
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
dispatcherTimer.Stop();
AllMyFunctions.logout_code(this);
}
private void restartTimer()
{
dispatcherTimer.Stop();
startTimer();
}
}
如何检测任何类型的用户交互以触发 restartTimer() 方法?
我在每个 PhoneApplicationPage 的 Tap 上添加了一个事件。
int timeOutInSeconds;
Timer timerObject;
private void onPageLoad()
{
timeOutInSeconds = 30;
timerObject = new Timer();
timerObject.startTimer(this, timeOutInSeconds, appsettings);
}
private void LayoutRoot_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
timerObject.restartTimer(timeOutInSeconds);
}
public class Timer
{
public DispatcherTimer dispatcherTimer;
public PhoneApplicationPage phoneApplicationPage;
public IsolatedStorageSettings appsettings;
//public Timer(PhoneApplicationPage callingPhoneApplicationPage)
//{
// this.phoneApplicationPage = callingPhoneApplicationPage;
//}
public void startTimer(PhoneApplicationPage callingPhoneApplicationPage, int noOfSeconds, IsolatedStorageSettings calledAppsettings)
{
this.appsettings = calledAppsettings;
this.phoneApplicationPage = callingPhoneApplicationPage;
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(timer_time_done);
dispatcherTimer.Interval = new TimeSpan(0, 0, noOfSeconds);
dispatcherTimer.Start();
}
public void timer_time_done(object sender, EventArgs e)
{
dispatcherTimer.Stop();
BsgFunctions.logout_Forcefully_code(phoneApplicationPage, this, appsettings);
}
public void restartTimer(int noOfSeconds)
{
dispatcherTimer.Stop();
startTimer(phoneApplicationPage, noOfSeconds,appsettings);
}
public void stopTimer()
{
dispatcherTimer.Stop();
}
}
我启动 DispatcherTimer 的代码。
我只需要检测任何类型的用户 Ineraction 以重新启动 DispatcherTimer?
public partial class MainMenu : PhoneApplicationPage
{
public MainMenu()
{
InitializeComponent();
startTimer();
}
private DispatcherTimer dispatcherTimer;
private void startTimer()
{
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
dispatcherTimer.Stop();
AllMyFunctions.logout_code(this);
}
private void restartTimer()
{
dispatcherTimer.Stop();
startTimer();
}
}
如何检测任何类型的用户交互以触发 restartTimer() 方法?
我在每个 PhoneApplicationPage 的 Tap 上添加了一个事件。
int timeOutInSeconds;
Timer timerObject;
private void onPageLoad()
{
timeOutInSeconds = 30;
timerObject = new Timer();
timerObject.startTimer(this, timeOutInSeconds, appsettings);
}
private void LayoutRoot_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
timerObject.restartTimer(timeOutInSeconds);
}
public class Timer
{
public DispatcherTimer dispatcherTimer;
public PhoneApplicationPage phoneApplicationPage;
public IsolatedStorageSettings appsettings;
//public Timer(PhoneApplicationPage callingPhoneApplicationPage)
//{
// this.phoneApplicationPage = callingPhoneApplicationPage;
//}
public void startTimer(PhoneApplicationPage callingPhoneApplicationPage, int noOfSeconds, IsolatedStorageSettings calledAppsettings)
{
this.appsettings = calledAppsettings;
this.phoneApplicationPage = callingPhoneApplicationPage;
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(timer_time_done);
dispatcherTimer.Interval = new TimeSpan(0, 0, noOfSeconds);
dispatcherTimer.Start();
}
public void timer_time_done(object sender, EventArgs e)
{
dispatcherTimer.Stop();
BsgFunctions.logout_Forcefully_code(phoneApplicationPage, this, appsettings);
}
public void restartTimer(int noOfSeconds)
{
dispatcherTimer.Stop();
startTimer(phoneApplicationPage, noOfSeconds,appsettings);
}
public void stopTimer()
{
dispatcherTimer.Stop();
}
}