开发者

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. B开发者_如何学Cut who changed the InvokeReuqired property while it is working. Please check this image:

When does the vaIue of the InvokeRequired property change?


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.


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜