如果您没有在x分钟内在我的应用程序中进行复制,则可能是这样。然后程序关闭了几分钟?有人可以向我解释我该如何处理吗?
编辑: 我希望我的应用程序在2分钟内例如没有主体复制时关闭。
我该如何解决我的问题?
这是我的代码。
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
{
const int WM_DRAWCLIPBOARD = 0x308;
if (m.Msg == WM_DRAWCLIPBOARD)
{
// Kopieert en kijkt of het overeen komt met de list
var text = Clipboard.GetText(TextDataFormat.UnicodeText);
// als je gekopieert hebt reset de clipboard
if (!string.IsNullOrEmpty(text))
{
timer1.Interval = 15000;
GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
Clipboard.Clear();
}
}
}
}
private void Timer1_Tick(object sender, EventArgs e)
{
this.Close();
}
}
}
答案 0 :(得分:1)
首先在主窗体上放置一个Timer
组件,并将其Interval
设置为所需的分钟数(该值以毫秒为单位,因此请确保计算正确)
现在将计时器的“启用”属性设置为true
在Tick
事件中,您只需要编写代码即可退出应用程序。
现在,每次进行复制/粘贴操作时,都可以像这样重置计时器
Timer1.Interval = xxx;
其中xxx是毫秒值
可以重置计时器here
应该这样做
在您的情况下,它将看起来像这样
if (!string.IsNullOrEmpty(text))
{
timer1.Enabled = false; // stop the timer
// do code here that can take some time...
GetAnswer(Clipboard.GetText(TextDataFormat.UnicodeText));
Clipboard.Clear();
timer1.Interval = 15000; // reset the timer
timer1.Enabled = true; // and start it again
}