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. Get the current thread ID in c#?

Get the current thread ID in c#?

Scheduled Pinned Locked Moved C#
questioncsharplearning
4 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.
  • B Offline
    B Offline
    Bog
    wrote on last edited by
    #1

    Hello, I have a c# assembly that gets called by unmanaged code (it gets called by Internet Explorer, like a plugin). What I want to know is, how do I get the thread ID of the current thread? If I use System.Threading.Thread.CurrentThread, I can only get the name. As I understand it, C# threads are not the same thing as old win32 threads. But since my C# assembly is being called by unmanaged code, it is definately running on one of those win32 threads, how do I get the thread ID? thank you "Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read." -Groucho Marx

    R I 3 Replies Last reply
    0
    • B Bog

      Hello, I have a c# assembly that gets called by unmanaged code (it gets called by Internet Explorer, like a plugin). What I want to know is, how do I get the thread ID of the current thread? If I use System.Threading.Thread.CurrentThread, I can only get the name. As I understand it, C# threads are not the same thing as old win32 threads. But since my C# assembly is being called by unmanaged code, it is definately running on one of those win32 threads, how do I get the thread ID? thank you "Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read." -Groucho Marx

      R Offline
      R Offline
      Red Rover
      wrote on last edited by
      #2

      Have you tried the GetCurrentThreadID() API? I know it's best to stick with the managed versions of the Win32 APIs, but this might give you what you want with no ill affects.

      1 Reply Last reply
      0
      • B Bog

        Hello, I have a c# assembly that gets called by unmanaged code (it gets called by Internet Explorer, like a plugin). What I want to know is, how do I get the thread ID of the current thread? If I use System.Threading.Thread.CurrentThread, I can only get the name. As I understand it, C# threads are not the same thing as old win32 threads. But since my C# assembly is being called by unmanaged code, it is definately running on one of those win32 threads, how do I get the thread ID? thank you "Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read." -Groucho Marx

        I Offline
        I Offline
        Ista
        wrote on last edited by
        #3

        Well Thread.GetHashCode Will but as you guessed its a managed thread ID which isnt a win32 id because really it runs in appDomains and other factors. The key word is managed AKA hosted **Note** An operating-system ThreadId has no fixed relationship to a managed thread, because an unmanaged host can control the relationship between managed and unmanaged threads. Specifically, a sophisticated host can use the fiber API to schedule many managed threads against the same operating system thread, or to move a managed thread between different operating system threads. hope this helps I'm not an expert yet, but I play one at work. Yeah and here too.

        1 Reply Last reply
        0
        • B Bog

          Hello, I have a c# assembly that gets called by unmanaged code (it gets called by Internet Explorer, like a plugin). What I want to know is, how do I get the thread ID of the current thread? If I use System.Threading.Thread.CurrentThread, I can only get the name. As I understand it, C# threads are not the same thing as old win32 threads. But since my C# assembly is being called by unmanaged code, it is definately running on one of those win32 threads, how do I get the thread ID? thank you "Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read." -Groucho Marx

          I Offline
          I Offline
          Ista
          wrote on last edited by
          #4

          Also SYstem.AppDomain.GetCurrentThreadID I'm not an expert yet, but I play one at work. Yeah and here too.

          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