theodoros2008
Member
- Joined
- Jun 16, 2008
- Messages
- 5
- Programming Experience
- 1-3
Hello to all!
I have an application that scans for BT devices.When i dont use multithread, the app is freezing while it is scanning and defreeze while not.
I use the following code for MT at Form1_load
The content of scan_proc is:
It runs with a timer which call the scan_proc() every x sec.
My problem:When it is scanning for BT devices everything is running good,but when it comes to the point adding the results to the ListView2 i get and InvalidOperationException and the error is (I will translate it from greek since my VB 2008 express is giving me errors in greek,i dont know why)
The operation of the different thread is not valid:There was a access to ListView2 from a different thread that was original created.
Any help?What i am doing wrong?
I have an application that scans for BT devices.When i dont use multithread, the app is freezing while it is scanning and defreeze while not.
I use the following code for MT at Form1_load
VB.NET:
Dim t1 As System.Threading.Thread
t1 = New Threading.Thread(AddressOf scan_proc)
t1.Start()
The content of scan_proc is:
VB.NET:
Dim devices As BluetoothDeviceInfo() = btClient.DiscoverDevices(10, True, True, True)
For i As Integer = 0 To devices.Length - 1
ListView2.Items.Add(devices(i).DeviceName + " " + Now)
DataGridView1.Rows.Insert(0, devices(i).DeviceName, DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString())
Next
My problem:When it is scanning for BT devices everything is running good,but when it comes to the point adding the results to the ListView2 i get and InvalidOperationException and the error is (I will translate it from greek since my VB 2008 express is giving me errors in greek,i dont know why)
The operation of the different thread is not valid:There was a access to ListView2 from a different thread that was original created.
Any help?What i am doing wrong?
Last edited: