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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SendMessageCallback() - what is execution context of callback function

SendMessageCallback() - what is execution context of callback function

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
3 Posts 2 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.
  • D Offline
    D Offline
    Derell Licht
    wrote on last edited by
    #1

    I have a technique that I use in WinAPI programs, to avoid stalling the message queue. I start a separate thread in my program, which opens a hidden window with its own message queue. I typically call this thread the CommTask thread, since the first time I did this was to handle slow serial communications. When I want to perform a time-consuming task, I send a message to the CommTask thread using SendMessageCallback(), with a data packet telling it what to do. When the CommTask thread completes handling of my message, my callback function gets executed. What I don't know is, what thread is the callback function executing in?? Is it still in the CommTask thread, or has it somehow returned to my main program thread, or is there some other thread context that it executes in?

    CPalliniC 1 Reply Last reply
    0
    • D Derell Licht

      I have a technique that I use in WinAPI programs, to avoid stalling the message queue. I start a separate thread in my program, which opens a hidden window with its own message queue. I typically call this thread the CommTask thread, since the first time I did this was to handle slow serial communications. When I want to perform a time-consuming task, I send a message to the CommTask thread using SendMessageCallback(), with a data packet telling it what to do. When the CommTask thread completes handling of my message, my callback function gets executed. What I don't know is, what thread is the callback function executing in?? Is it still in the CommTask thread, or has it somehow returned to my main program thread, or is there some other thread context that it executes in?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      The documentation[^] hints at calling thread context. In any case you may easily verify it calling GetCurrentThreadId[^] inside the callback function.

      Veni, vidi, vici.

      In testa che avete, signor di Ceprano?

      D 1 Reply Last reply
      0
      • CPalliniC CPallini

        The documentation[^] hints at calling thread context. In any case you may easily verify it calling GetCurrentThreadId[^] inside the callback function.

        Veni, vidi, vici.

        D Offline
        D Offline
        Derell Licht
        wrote on last edited by
        #3

        Excellent idea!! Thank you, GetCurrentThreadId() will immediately and directly answer this question for me, I'll test it out this morning... Yep, GetCurrentThreadId() confirmed that the callback thread executes in the context of the initiating thread.

        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