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: 
Polling the clipboard with a timer is very bad practice. The clipboard is a shared resource, and you'll be interfering with other apps that are monitoring the clipboard (via proper clipboard notification, i.e. following the rules). And you'll be colliding with whatever the user is trying to do. For example, when the user attempts to copy data to the clipboard, and you have opened it in your polling loop to examine it, he'll get "cannot open clipboard" errors or crashes. Please read up on clipboard viewers in MSDN: <http://msdn.microsoft.com/en-us/library/ff468802(v=VS.85).aspx>
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/>