title: Exception thrown: 'System.InvalidOperationException' in PresentationCore.dll
body: <p>I have gone through many other questions on this error but couldn't resolve mine. So I am asking this from the professionals who can guide me how to resolve.</p>
  <p>Here is the code which is giving me this error.</p>
  <pre><code>class MainClass
  {
      static void Main(string[] args)
      {
          {
              Clock myClock = new Clock();
  
              while (myClock.Hour.Value &lt; 24)
              {
                  myClock.Tick();
                  if (Keyboard.IsKeyDown(Key.Space))
                  {
                      myClock.ResetClock();
                  }
              }
         
          Console.ReadLine();
          }
      }
  }
  </code></pre>
  <p>The exception is showing after Key.Space</p>
  <p>After going through stack I have added</p>
  <pre><code>Application.Current.Dispatcher.Invoke(new Action(() =&gt; 
  </code></pre>
  <p>below the static void even then it raised the error. Would be really great if you guys can throw some light on this issue and where and what shall I do to erase this and get my application to work. More info on this error also came.</p>
  <blockquote>
  <p>An unhandled exception of type 'System.InvalidOperationException' occurred         in PresentationCore.dll</p>
  <p>Additional information: The calling thread must be STA, because many UI components require this.</p>
  </blockquote>
  <p>I am creating a C# clock through GUI.</p>
  <p>Thanks a lot</p>