how to get the address of a thread
-
I'm developing a 'socket programming solution for client server architecture'. There a client connects to a server and send messages. But i got this error,"cross thread operation not valid" and found a solution as follows. It has to pass the thread address but i dont know how to obtain a thread address. Could you please tell me how to obtain a thread address. This is the solution i found. ---------------------------------------- Thread mythread = new Thread(addressOf thread1); mythread.start(); Sub MyThread1 ' Working code ' Working code ' Working code ' Working code ' Working code ' Working code AccessControl(); End Sub -------------------------------- Thank you. sweenySL
-
I'm developing a 'socket programming solution for client server architecture'. There a client connects to a server and send messages. But i got this error,"cross thread operation not valid" and found a solution as follows. It has to pass the thread address but i dont know how to obtain a thread address. Could you please tell me how to obtain a thread address. This is the solution i found. ---------------------------------------- Thread mythread = new Thread(addressOf thread1); mythread.start(); Sub MyThread1 ' Working code ' Working code ' Working code ' Working code ' Working code ' Working code AccessControl(); End Sub -------------------------------- Thank you. sweenySL
It not the address of the thread, it is a delegate for the method to invoke when the thread begins execution. Check the documentation on MSDN. Here is a sample. Public Class Test _ Shared Sub Main() Dim newThread As New Thread(AddressOf Work.DoWork) newThread.Start() End Sub End Class Public Class Work Private Sub New() End Sub Shared Sub DoWork() End Sub End Class
-
I'm developing a 'socket programming solution for client server architecture'. There a client connects to a server and send messages. But i got this error,"cross thread operation not valid" and found a solution as follows. It has to pass the thread address but i dont know how to obtain a thread address. Could you please tell me how to obtain a thread address. This is the solution i found. ---------------------------------------- Thread mythread = new Thread(addressOf thread1); mythread.start(); Sub MyThread1 ' Working code ' Working code ' Working code ' Working code ' Working code ' Working code AccessControl(); End Sub -------------------------------- Thank you. sweenySL
Hi Actually you don't have to obtain the address of a thread instead you provide the name of a function (Your thread function) and .net will find the address for you . AddressOf is a VB.net keyword that returns the address of a callback function.In C# you don't have to use any keywords . For example:
Thread myThread=new Thread(new ThreadStart(MyFunction)); myThread.Start();
That MyFunction is a call back function that will be called when the thread is started and the ThreadStart is a delegate to MyFunction. Regards -
It not the address of the thread, it is a delegate for the method to invoke when the thread begins execution. Check the documentation on MSDN. Here is a sample. Public Class Test _ Shared Sub Main() Dim newThread As New Thread(AddressOf Work.DoWork) newThread.Start() End Sub End Class Public Class Work Private Sub New() End Sub Shared Sub DoWork() End Sub End Class
-
Hi Actually you don't have to obtain the address of a thread instead you provide the name of a function (Your thread function) and .net will find the address for you . AddressOf is a VB.net keyword that returns the address of a callback function.In C# you don't have to use any keywords . For example:
Thread myThread=new Thread(new ThreadStart(MyFunction)); myThread.Start();
That MyFunction is a call back function that will be called when the thread is started and the ThreadStart is a delegate to MyFunction. Regards