/// <summary> /// 监听剪贴板更新事件,会执行两遍以上 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnClipboardUpdated(object sender, EventArgs e) { #region 执行第二遍时跳过 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; } #endregion AllowStatus isListenClipboard = SettingsManager.GetInstance().IsListenClipboard(); if (isListenClipboard != AllowStatus.YES) { return; } string input; try { IDataObject data = Clipboard.GetDataObject(); string[] fs = data.GetFormats(); input = data.GetData(fs[0]).ToString(); } catch (Exception exc) { Console.WriteLine("OnClipboardUpdated()发生异常: {0}", exc); LogManager.Error("OnClipboardUpdated", exc); return; } SearchService searchService = new SearchService(); searchService.BiliInput(input + AppConstant.ClipboardId, ViewIndexViewModel.Tag, eventAggregator); }