I have never exactly understood why UI controls are not thread safe. I guess there are perfectly good reasons, but it does strike me as unfortunate that there is no way (at least that I know of) of running the standard UI controls in a thread-safe mode.
Predictably I now have a UI which needs to be thread safe.
Typically of course I would want to write:-
SomeTextBox.AppendText(someString)
But of course I can't do that. So I can abstract the UI Updates into a different class and write instead:-
XTUI.AppendText(someTextBox,someString)
And:-
Delegate Sub TSAppendTextCallback(ByVal t As TextBox, ByVal s As String)
Shared Sub AppendText(byval someTextBox,someString)
However, this is obviously a right royal pain in the butt. There must be a better way. The world and his dog must be writing multi threaded UI's. However, I have been unable as yet to find a better approach. Any suggestions?
Predictably I now have a UI which needs to be thread safe.
Typically of course I would want to write:-
SomeTextBox.AppendText(someString)
But of course I can't do that. So I can abstract the UI Updates into a different class and write instead:-
XTUI.AppendText(someTextBox,someString)
And:-
Delegate Sub TSAppendTextCallback(ByVal t As TextBox, ByVal s As String)
Shared Sub AppendText(byval someTextBox,someString)
If t.InvokeRequired Then
t.Invoke(New TSAppendTextCallback(AddressOf TSAppendText), t, s)
Elset.AppendText(s)
End IfHowever, this is obviously a right royal pain in the butt. There must be a better way. The world and his dog must be writing multi threaded UI's. However, I have been unable as yet to find a better approach. Any suggestions?
Comment