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.
Here is the code which is giving me this error.
class MainClass
{
static void Main(string[] args)
{
{
Clock myClock = new Clock();
while (myClock.Hour.Value < 24)
{
myClock.Tick();
if (Keyboard.IsKeyDown(Key.Space))
{
myClock.ResetClock();
}
}
Console.ReadLine();
}
}
}
The exception is showing after Key.Space
After going through stack I have added
Application.Current.Dispatcher.Invoke(new Action(() =>
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.
An unhandled exception of type 'System.InvalidOperationException' occurred in PresentationCore.dll
Additional information: The calling thread must be STA, because many UI components require this.
I am creating a C# clock through GUI.
Thanks a lot