Difference between revisions of "Marshalling updates to a text box"
From RayHarwood
Rayharwood (Talk | contribs) (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...") |
Rayharwood (Talk | contribs) |
||
| 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 | ||