[英]Exit application after x minutes of clipboard.gettext inactivity of Windows
如果您在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();
}
}
}
1首先在主窗體上放置一個Timer
組件,並將其Interval
設置為所需的分鍾數(該值以毫秒為單位,因此請確保計算正確)
現在將計時器的Enabled屬性設置為true
在Tick
事件中,您只需要編寫代碼即可退出應用程序。
現在,每次進行復制/粘貼操作時,請像這樣重置計時器
Timer1.Interval = xxx;
其中xxx是值(以毫秒為單位)
重置計時器可以在這里找到
那應該做
在您的情況下,它將看起來像這樣
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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.