I'm trying to detect every time the clipboard data changes. And so, I set a timer and have it continuously check Clipboard.GetText()
for changes.
I'm using the following code:
public void WaitForNewClipboardData()
{
//This is in WPF, Timer comes from System.Timers
Timer timer = new Timer(100);
timer.Elapsed += new ElapsedEventHandler(
delegate(object a, ElapsedEventArgs b){
if (Clipboard.GetText() != ClipBoardData)
{
SelectedText.Text = Clipboard.GetText();
ClipBoardData = Clipboard.GetText();
timer.Stop();
}
});
timer.Start();
}
I get the following error when it runs:
Current thread must be set to singlethread apartment (STA) mode before OLE calls can be made.
Does anyone know why?