Hello im new to this site so forgive me if I have broken any rules here...
I am writing a test application to aid me in the Threading class
how ever when i invoke (for thread safety) the process actualy runs on the same thread, I have looked everywhere on line for an answer but no dice...
My source code is as follows...
Imports System.Threading
Public Class Form
Private pass As Integer = 0
Private Delegate Sub CallBack(ByVal No As Integer)
Public Sub New()
InitializeComponent()
Me.Text = "MultiThreading - Main Thread ID: " & Thread.CurrentThread.ManagedThreadId
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Dim t As Thread = New Thread(AddressOf AddItem, 0)
t.GetHashCode()
t.SetApartmentState(ApartmentState.MTA)
t.IsBackground = True
t.Start(pass)
pass = pass + 1
End Sub
Private Sub AddItem(ByVal ItemNo As Integer)
If ListBox.InvokeRequired = True Then
ListBox.BeginInvoke(New CallBack(AddressOf AddItem), ItemNo)
Else
ListBox.Items.Add("Item Number " & ItemNo & " - Added by Thread ID: " & Thread.CurrentThread.ManagedThreadId)
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As Thread = New Thread(AddressOf MSGTest)
t.Start("Test Message")
End Sub
Private Sub MSGTest(ByVal MSG As String)
MsgBox(MSG & "... MsgBox Generated by Thread ID: " & Thread.CurrentThread.ManagedThreadId, MsgBoxStyle.Information, "Thread Test")
End Sub
End Class
The test function works but that does not use any invoke,
Any help would be great as I have spent some time working this one out.
Thanks in advanced... Blingking01