I really cant understand this behavior and was hoping someone could explain that to me. Consider that I want to update my button text from another thread :
Task.Factory.StartNew((() =>
{
button1.Text = "Hello";
}));
From what I understand, I shouldn't be able to do this because I am in another thread but somehow this works, but if I add this line to the code :
Task.Factory.StartNew((() =>
{
Thread.Sleep(500);
button1.Text = "Hello";
}));
Then it gives me : "Cross-thread operation not valid" but now there is 2 questions.
1.) Why does code 1 allow me to change button text from another thread?
2.) Why does code 2 crash when I added that line of code?
EDIT : Just to point out, my main questions is why its allowing me in the first code to update UI content while it crashes in the second code, not if Task.Factory.StartNew spawns a new thread or not.