C
ChunkyMonkey
Howdy
In my startup form, I start up a thread for a function that I want to run in
the background(the function just polls a system every second). See first
section of code below.
What I am doing at the moment, is in the new thread, I load a form, and this
form has a timer that when it ticks, get the status of a remote machine. At
the moment on every tick, it add an item to a list box which is just the
now() value so that I can see it working
This all works fine.
The issue is that I want the new thread that is polling the machine, to
update the main thread, and call a function in my startup form.
I tried in my timer event, to call the public function in my startup form,
just passing some text, but nothing happens.
What do I need to do, so that the new thread can call functions on the
frmMain...
Code:
--------
'Startup Form(frmMain) code creating new thread....
Dim PollingThread As New Thread(AddressOf PollLift)
PollingThread.IsBackground = True
PollingThread.Name = "Polling"
PollingThread.Start()
--------------
Public Function PollLift() As Boolean
Dim frmPolling As New frmComms
frmPolling.ShowDialog()
frmPolling.Timer1.Enabled = True
End Function
' in the frmPolling form there is a timer..
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
ListBox1.Items.Add("Tick" & Now)
frmMain.LiftUpdate(Now)
End Sub
' in the frmMain....
Public Function LiftUpdate(ByVal strText As String)
lblThread.Text = strText
End Function
In my startup form, I start up a thread for a function that I want to run in
the background(the function just polls a system every second). See first
section of code below.
What I am doing at the moment, is in the new thread, I load a form, and this
form has a timer that when it ticks, get the status of a remote machine. At
the moment on every tick, it add an item to a list box which is just the
now() value so that I can see it working
This all works fine.
The issue is that I want the new thread that is polling the machine, to
update the main thread, and call a function in my startup form.
I tried in my timer event, to call the public function in my startup form,
just passing some text, but nothing happens.
What do I need to do, so that the new thread can call functions on the
frmMain...
Code:
--------
'Startup Form(frmMain) code creating new thread....
Dim PollingThread As New Thread(AddressOf PollLift)
PollingThread.IsBackground = True
PollingThread.Name = "Polling"
PollingThread.Start()
--------------
Public Function PollLift() As Boolean
Dim frmPolling As New frmComms
frmPolling.ShowDialog()
frmPolling.Timer1.Enabled = True
End Function
' in the frmPolling form there is a timer..
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
ListBox1.Items.Add("Tick" & Now)
frmMain.LiftUpdate(Now)
End Sub
' in the frmMain....
Public Function LiftUpdate(ByVal strText As String)
lblThread.Text = strText
End Function