Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7458313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:25:53+00:00 2026-05-29T13:25:53+00:00

For example, I have a main thread, there is created a lot of classes

  • 0

For example, I have a main thread, there is created a lot of classes and etc. I have a network part, that wait for client data in separate thread. This “waiter” should run some functions from classes that was created in main thread and this functions should be executed in main thread.

How could I do so? If i call needed methods this way SomeClass::SomeMethod(some_args); from waiter, sure, they executes in secondary thread.

Would be good have something like this:
SomeClass::Invoke(function_pointer); so, the function that function_pointer points on would be executed in main thread? I need an advice for windows OS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T13:25:53+00:00Added an answer on May 29, 2026 at 1:25 pm

    If this is Windows Win32 application, then using the application’s Message processing queue is a common approach.
    In the main window of your app you wait for a custom user message, typically it will be something like:

    (in header file)
    #define WM_MYCUSTOMMESSAGE (WM_USER + 1)
    
    (WndProc for you main window)
    LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
        case WM_MYCUSTOMMESSAGE:
            ... Process something
            break;
        }
    }
    
    (On seconday thread)
    SendMessage(hWnd, WM_MYCUSOMMESSAGE, wParam, lParam); // Send and wait for the result
    
    PostMessage(hWnd, WM_MYCUSTOMMESSAGE, wParam, lParam); // Send the message and continue this thread.
    

    [EDIT]
    For a Console application, try using Windows Events. So create a named Event using:

    (On primary thread)
    HANDLE myEvent = CreateEvent(NULL, FALSE, FALSE, "MyEvent");
    
    ... later as part of a message processing loop
    while(true)
    {
        WaitForSingleObject( myEvent, 0 ); // Block until event is triggers in secondary thread
    
        ... process messages here
        ... I recommend storing "messages" in a synchronized queue
    }
    
    (On secondary thread)
    SetEvent(myEvent); // Triggers the event on the main thread.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's consider the below example. There, I have: target MAIN calls target t and
I have 3 classes in my example: Class A, the main activity. Class A
Is there a way to have the parent that spawned a new thread catch
If you have worked with gui toolkits, you know that there is a event-loop/main-loop
For example: This is main body of my content. I have a footnote link
I have the following example, compiled in VS2005, warning level 4: int main(int argc,
Most of our Eclipse projects have multiple source folders, for example: src/main/java src/test/java When
I have a java application where the main-thread starts 2 other threads. If one
I have a class that fetches data in response to button presses in the
I have a method running in a seperate thread. The thread is created and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.