启动DispatcherTimer的代码。
我只需要检测任何类型的用户Ineraction以重启DispatcherTimer?
[WebMethod]
public string[] GetCompletionList(string prefixText)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("select Company_name from Outword_CommonMST where Company_name " +
"like '" + prefixText + "%' order by company_name", con);
//cmd.Parameters.AddWithValue("@Name", prefixText);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable( );
da.Fill(dt);
List<string> Company_name = new List<string>();
for(int i=0;i<dt.Rows.Count;i++)
{
Company_name.Add(dt.Rows[i][0].ToString());
}
return Company_name.ToArray();
}
}
如何检测任何类型的用户交互以触发restartTimer()方法?
答案 0 :(得分:0)
我在每个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();
}
}