Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to get the address of a thread

how to get the address of a thread

Scheduled Pinned Locked Moved C#
sysadminarchitecturehelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sweenySL
    wrote on last edited by
    #1

    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

    R B 2 Replies Last reply
    0
    • S 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

      R Offline
      R Offline
      roel_v
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • S 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

        B Offline
        B Offline
        beatles1692
        wrote on last edited by
        #3

        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

        S 1 Reply Last reply
        0
        • R roel_v

          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

          S Offline
          S Offline
          sweenySL
          wrote on last edited by
          #4

          Hi, Thanx alot for your reply. :) sweenySL

          1 Reply Last reply
          0
          • B beatles1692

            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

            S Offline
            S Offline
            sweenySL
            wrote on last edited by
            #5

            Hi:) Thank you so much for your reply. Hence im not much familier with C# it helped me alot. Once again thank you so much.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups