uzay95
uzay95

Reputation: 16632

When does the vaIue of the InvokeRequired property change?

When i want to use delegate class to make call while windows form working, i always have to use InvokeRequired. It is ok. But who changed the InvokeReuqired property while it is working. Please check this image: alt text

Upvotes: 3

Views: 1180

Answers (3)

Donut
Donut

Reputation: 112825

InvokeRequired is true when the control is accessed from a thread other than the thread it was created on, and false otherwise.
To more directly answer your question, it's not that the InvokeRequired property "changes" at a specific point in time; it's more accurate to say that it may return different values based on the thread you access it from.

Upvotes: 6

Charles Bretana
Charles Bretana

Reputation: 146499

What do you mean "change the InvokeRequired property" ? Do you mean that the true/false value is changing ? If it returns true, and you make the delegate call to BeginInvoke, then after that, in the delegate, the value better have changed. The whole point is to "switch" to the thread that the control was created on. When a line of code with InvokeRequired is executed on any thread other than the thread the control was created on, InvokeRequired will return true. Only when executed on the same thread the control was created on will it return false. The property could have been named NotOnThreadIWasCreatedIn, cause thats really all it's doing. It's named InvokeRequired to coomunicate what it needs to be used for...

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1500665

You're calling Delegate.BeginInvoke in button1_Click, which means SayListeyeEkle will be called in a thread-pool thread - which means it's entirely correct for InvokeRequired to be true. It wouldn't be true if you called ListeyeEkle directly from button1_Click, in the UI thread.

Upvotes: 4

Related Questions