<分区>
我有一个 WPF
应用程序,其中有一个注册窗口。
当我单击注册选项卡时,它会打开注册窗口。
我的要求是,如果在单击注册选项卡后没有任何事件,它应该超时并移动到另一个窗口。
<分区>
我有一个 WPF
应用程序,其中有一个注册窗口。
当我单击注册选项卡时,它会打开注册窗口。
我的要求是,如果在单击注册选项卡后没有任何事件,它应该超时并移动到另一个窗口。
最佳答案
我认为你需要检查窗口上的空闲时间
在windows加载事件上
private static DispatcherTimer idleTimer;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
idleTimer = new DispatcherTimer();
idleTimer.Interval = TimeSpan.FromSeconds(5);
idleTimer.Tick += this.OnTimerTick;
idleTimer.Start();
}
计时器滴答事件
private void OnTimerTick(object sender, EventArgs e)
{
uint idleTime = this.GetIdleTime();
if (idleTime > 5000)
{
this.Close();
}
}
空闲时间助手方法
[DllImport("User32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO dummy);
private uint GetIdleTime()
{
LASTINPUTINFO lastUserAction = new LASTINPUTINFO();
lastUserAction.CbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastUserAction);
GetLastInputInfo(ref lastUserAction);
return (uint)Environment.TickCount - lastUserAction.DwTime;
}
internal struct LASTINPUTINFO
{
public uint CbSize;
public uint DwTime;
}
关于c# - 如何在两个窗口之间的 Wpf 应用程序中保持 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34528656/