解决监听剪贴板事件连续执行2次的问题

croire 3 years ago
parent e0f3c978cd
commit c48ecc86c9

@ -149,6 +149,7 @@ namespace DownKyi.ViewModels
clipboardHooker = new ClipboardHooker(Application.Current.MainWindow); clipboardHooker = new ClipboardHooker(Application.Current.MainWindow);
clipboardHooker.ClipboardUpdated += OnClipboardUpdated; clipboardHooker.ClipboardUpdated += OnClipboardUpdated;
// 进入首页
var param = new NavigationParameters var param = new NavigationParameters
{ {
{ "Parent", "" }, { "Parent", "" },
@ -292,8 +293,32 @@ namespace DownKyi.ViewModels
icon.Fill = DictionaryResource.GetColor("ColorSystemBtnTintDark"); icon.Fill = DictionaryResource.GetColor("ColorSystemBtnTintDark");
} }
#region 剪贴板
private int times = 0;
/// <summary>
/// 监听剪贴板更新事件,会执行两遍以上
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void OnClipboardUpdated(object sender, EventArgs e) private void OnClipboardUpdated(object sender, EventArgs e)
{ {
times += 1;
DispatcherTimer timer = new DispatcherTimer
{
Interval = new TimeSpan(0, 0, 0, 0, 300)
};
timer.Tick += (s, ex) => { timer.IsEnabled = false; times = 0; };
timer.IsEnabled = true;
if (times % 2 == 0)
{
timer.IsEnabled = false;
times = 0;
return;
}
AllowStatus isListenClipboard = SettingsManager.GetInstance().IsListenClipboard(); AllowStatus isListenClipboard = SettingsManager.GetInstance().IsListenClipboard();
if (isListenClipboard != AllowStatus.YES) if (isListenClipboard != AllowStatus.YES)
{ {
@ -381,5 +406,7 @@ namespace DownKyi.ViewModels
} }
} }
#endregion
} }
} }

Loading…
Cancel
Save