Thank you both for taking the time to respond.
I should have posted my the code so so you two could see where I'm
coming from, sorry about that.
Some background on the actual program I wrote and want to change:
I already wrote( for personal use) a program that uses the background
component. While this proram runs fine I want better control/options
of the background thread so I want to use the system.thread way of
doing it.
Most of the processing are done in several modules which may be used
seperately or done one after the other though only one background run
at a time. All of these modules have programs that will display
information in the main UI while running.
The "testbutton" only purpose is to represent several controls (from
the program mentioned above) that are disabled and must be reenabled
after the background thread ends.
So I wrote this test project to help me undertstand delegates and
control.invoke updates. It is written to basically emulate how the
actual program works when it comes to updating the controls. I used
someone else's code on the internet, I removed the extra stuff and
made some changes so it reflects how I need to update the textbox.
Like the main program this code will:
1) start a background process at the button click.
The sub that is run is in a module where it must stay.
2) As the thread runs the sub will update the main form by
* sending the text to be displayed
*sending a control code (represented initially by the ctr
variable)
*pausing the worker thread. Pausing takes place in the worker
thread and the pause duration will vary
3) repeat til done
Now that the updating part works, what I need now is to alert the main
UI that the thread is completed so the main UI does the reenabling of
the controls.
So after the thread that runs the "startprocess" is completed, how do
I trigger the main UI to call the enablebuttons() sub?
I see only doing a series of control.invokes if the only way is to
have the background thread be the trigger.
Please let me know if both your sample codes will still work now that
I presented the test code.
Thank you both very much for helping.
------------------------------------------------
Imports System.Threading
Public Class Form1
Dim xctr As Integer
Private Delegate Sub UpDateGSLDelegate(ByVal txt As String, ByVal
rpn As Integer)
Public Sub updateTxtBox(ByVal txt As String, ByVal rpn As Integer)
If txtBoxtest.InvokeRequired Then
Invoke(New UpDateGSLDelegate(AddressOf UpDateTheGSL), txt,
rpn)
Else
UpDateTheGSL(txt, rpn)
End If
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
Dim t1 As New System.Threading.Thread(AddressOf startproces)
testbutton.Enabled = False
t1.Start()
End Sub
Private Sub enablebuttons()
testbuttont.Enabled = True
End Sub
Public Sub UpDateTheGSL(ByVal txt As String, ByVal rpn As Integer)
txtBoxtest.Text = txt & rpn
End Sub
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
MainForm = Nothing
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
MainForm = Me
End Sub
End Class
----------------------------------------------
Module Module2
Public MainForm As Form1
Public Sub startProcess()
For ctr As Integer = 0 To 5
UpdateMainForm("kkjkjkjk", ctr, 1000)
Next
End Sub
Sub UpdateMainForm(ByVal txt As String, ByVal rpn As Integer,
ByVal xsleep As Integer)
MainForm.updateTxtBox(txt, rpn)
System.Threading.Thread.Sleep(xsleep)
End Sub
End Module