Question: 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?

Answer: 
Not entirely sure with this but have you tried invoking the changing of text? I had the exact same error (although in a very different scenario) and invoking a method to change a control property solved it.

I created a delegate with a string parameter:

```
public delegate void TextBoxChangeDelegate(string text);

```

Then a method that will do the actual changing:

```
void TextBoxChange(string text)
{
   MyTextBox.Text = text;
}

```

Then I invoke this method in my thread process (and in your case, the timer event):

```
public void ThreadService()
{
  while(Running)
  {
    Invoke(new TextBoxChangeDelegate(TextBoxChange), new object[] { "New Value: "+ strNewValue });
  }

}

```

This was in WinForms. It was back when I knew for the first time that changing control properties on a thread other than the UI thread causes problems. Sorry if this isn't even close to what you're trying.
Its because you can not use windows control in a thread delegate, basically timer is a thread and passing a delegate which using windows control is creating a problem.
check if this helps
<http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/2411f889-8e30-4a6d-9e28-8a46e66c0fdb/>