.NET: Control Invoke() in Reflector
Posted
by sheepsimulator
on Stack Overflow
See other posts from Stack Overflow
or by sheepsimulator
Published on 2010-05-09T19:03:06Z
Indexed on
2010/05/09
19:08 UTC
Read the original article
Hit count: 295
So, I was getting back into some .NET programming, and through a new feature in VS.NET 2010, it detected a case where I was trying to modify a control from a thread that didn't create that control, and pointed me to an article on MSDN about how you do this correctly...
' HOW TO WRITE TO A FORM CONTROL FROM A THREAD THAT DIDN'T CREATE THE CONTROL
' ===========================================================================
' Say you need to write to a UI text box that logs stuff...
Delegate Sub WriteLogDelegate(ByVal [text] As String)
Private Sub WriteLog(ByVal [text] As String)
If Me.rtfLog.InvokeRequired Then
' We are not in the same thread!
' Create new WriteLogDelegate and invoke it on the same thread
Dim d As New WriteLogDelegate(AddressOf WriteLog)
Me.rtfLog.Invoke(d, New Object() {[text]})
Else
' We are totally in the same thread...
' Call AppendText like normal!
Me.rtfLog.AppendText([text])
End If
End Sub
AND I WAS SO EXCITED BECAUSE I HAVE BEEN PUZZLED BY HOW TO DO THIS FOR LIKE 5 YEARS BECAUSE PREVIOUS VERSIONS OF VS.NET DIDN'T FLAG THIS SINCE I WAS AN UNDERGRAD ON A PROJECT AND...
Umm... Sorry bout that. Composure regained. Anyway, now that I know this bit of .NET-fu, I'd like to learn more about what's going on and how it works.
Where can I find the code for Invoke() in .NET Reflector?
© Stack Overflow or respective owner