Difference between revisions of "Marshalling updates to a text box"

From RayHarwood
Jump to: navigation, search
(Created page with "When you have a text box on a form, it's typically created as part of the form's initialization code, in the main thread. If you have a background thread that needs to update...")
 
Line 2: Line 2:
  
 
The code isn't difficult to write, but it is ''complex'', in that it's not intuitive nor easy to simply type out when you need it.
 
The code isn't difficult to write, but it is ''complex'', in that it's not intuitive nor easy to simply type out when you need it.
 +
 +
    Private Delegate Sub ShowText(Text As String)
 +
    '
 +
    Sub ShowText_Invoke(Text As String)
 +
        If tbActionLog.InvokeRequired Then
 +
            Dim SHowText_Delegate As New ShowText(AddressOf ShowText_Invoke)
 +
            SHowText_Delegate(Text)
 +
        Else
 +
            tbActionLog.Text &= Format(Now, "hh:mm:ss tt") & " " & Text & vbCrLf
 +
            tbActionLog.Select(tbActionLog.TextLength, 1)
 +
            tbActionLog.ScrollToCaret()
 +
            Application.DoEvents()
 +
        End If
 +
    End Sub

Revision as of 15:55, 24 March 2014

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox