I realize it's a bit late in the game for this (since wpf handles it so well), but i'm bored and killing time.
This simple walkthrough will show you how to post to a richtextbox on a seperate thread (could easily show a status bar for installing using this method).
First, of course, make a form and place a richtextbox on it.
Now, in your form's code, delegate a sub routine with one variable for string passing as such
Delegate Code:
Delegate Sub nameIt(ByVal value As String)
Now, I know this seems redundant to you first timers, but now you "Declare" your new Sub as follows:
Notice we declare this variable as the delegated sub, this will be usefull when we actually call upon the sub!Declare Code:
Private nameItDeclared as nameIt
Now create a simple sub routine (no invoking) to preform the action you want performed. The key here is simplicity! Grab only the direct part of your sub. In our case we are using the "append" method of the richtextbox, as so;
subRout Code:
Sub someSubRoutine(ByVal value As String) RichTextBox1.AppendText(value) End Sub
Now, go back a step and in your Form's "Load" event, establish your declaration from earlier, as such;
establish Code:
nameitDeclared = AddressOf someSubRoutine
This tells our form that our declared sub needs to use "someSubRoutine" as its established method, otherwise, nameItDeclared wouldn't do anything!
Now for the fun part, the use of it all!
For this I'm going to make things VERY SIMPLE!!!
Create a new sub called appendRTX and add the following
theUse Code:
Sub appendRTX(ByVal value As String) If RichTextBox1.InvokeRequired = True Then RichTextBox1.Invoke(nameitDeclared, value.ToString) Else someSubRoutine(value.ToString) End If End Sub
There you go!
Now to see it in action! Simply create a sub call Test
Test Code Code:
Sub Test() For i As Integer = 0 To 10000 appendRTX(i) Next End Sub
One Last thing! In your form's "Load" event (below our establied declaration) place the following code to start our test on new thread!
finally Code:
Dim newThread As Threading.Thread newThread.IsBackground = True newThread.Start(Test)
Follow all the directions right? This should work perfect and easy, course I ahvn't tested it cause i'm busy being bored, but if it breaks, someone i'm sure will tell me and i fix it?
hehehe :P
Enjoy peeps, see you all laters!




Reply With Quote