P
Paul
Hi,
I'm having a problem with my app. All its supposed to do is put the word
"Check" in a listbox every 2 seconds!
I'm getting a System.InvalidOperationException error, more specifically,
"Cross-thread operation not valid: Control 'ListBox1' accessed from a thread
other than the thread it was created on."
Please help! Here's my code...
Thanks, Paul
Imports System
Imports System.Timers
Public Class Form1
Dim mytimer As New System.Timers.Timer()
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
AddHandler mytimer.Elapsed, AddressOf OnTimedEvent
mytimer.Interval = 2000
mytimer.Enabled = True
mytimer.Start()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStop.Click
mytimer.Enabled = False
mytimer.Stop()
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
ElapsedEventArgs)
'My.Computer.FileSystem.WriteAllText("C:\test.log", "test", True)
ListBox1.Items.Add("Check..." & Date.Now())
End Sub
End Class
I'm having a problem with my app. All its supposed to do is put the word
"Check" in a listbox every 2 seconds!
I'm getting a System.InvalidOperationException error, more specifically,
"Cross-thread operation not valid: Control 'ListBox1' accessed from a thread
other than the thread it was created on."
Please help! Here's my code...
Thanks, Paul
Imports System
Imports System.Timers
Public Class Form1
Dim mytimer As New System.Timers.Timer()
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStart.Click
AddHandler mytimer.Elapsed, AddressOf OnTimedEvent
mytimer.Interval = 2000
mytimer.Enabled = True
mytimer.Start()
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStop.Click
mytimer.Enabled = False
mytimer.Stop()
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
ElapsedEventArgs)
'My.Computer.FileSystem.WriteAllText("C:\test.log", "test", True)
ListBox1.Items.Add("Check..." & Date.Now())
End Sub
End Class