public void BeginWatching(Models.SocketMessageHandler connectionToSendChanges)
 {
     if (ClipboardWatcher?.Enabled == true)
     {
         ClipboardWatcher.Stop();
     }
     ClipboardWatcher          = new System.Timers.Timer(500);
     ClipboardWatcher.Elapsed += (sender, args) =>
     {
         MainWindow.Current.Dispatcher.Invoke(() =>
         {
             try
             {
                 if (!Clipboard.IsCurrent(ClipboardData))
                 {
                     ClipboardData = Clipboard.GetDataObject();
                     var jsonData  = GetTransferData();
                     if (!string.IsNullOrWhiteSpace(jsonData.Format))
                     {
                         connectionToSendChanges.SendJSON(jsonData);
                     }
                 }
             }
             catch
             {
                 if (!connectionToSendChanges.IsConnected)
                 {
                     ClipboardWatcher.Stop();
                 }
             }
         });
     };
     ClipboardWatcher.Start();
 }
Beispiel #2
0
 public void BeginWatching(Models.SocketMessageHandler connectionToSendChanges)
 {
     try
     {
         if (ClipboardWatcher?.Enabled == true)
         {
             ClipboardWatcher.Stop();
         }
         ClipboardData = Clipboard.GetDataObject();
         Clipboard.SetDataObject(ClipboardData);
         ClipboardWatcher = new System.Timers.Timer(500);
     }
     catch
     {
         return;
     }
     ClipboardWatcher.Elapsed += (sender, args) =>
     {
         if (!Config.Current.IsClipboardShared)
         {
             ClipboardWatcher.Stop();
             return;
         }
         MainWindow.Current.Dispatcher.Invoke(() =>
         {
             try
             {
                 if (!Clipboard.IsCurrent(ClipboardData))
                 {
                     ClipboardData = Clipboard.GetDataObject();
                     var jsonData  = GetTransferData();
                     if (!string.IsNullOrWhiteSpace(jsonData.Format))
                     {
                         connectionToSendChanges.SendJSON(jsonData);
                     }
                 }
             }
             catch (Exception ex)
             {
                 if (connectionToSendChanges?.IsConnected != true)
                 {
                     ClipboardWatcher.Stop();
                 }
                 else
                 {
                     Utilities.WriteToLog(ex);
                 }
             }
         });
     };
     ClipboardWatcher.Start();
 }