CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2006
    Posts
    12

    Multithreaded Console application similar to windows Application.

    I am creating a multi-threading console application where the primary thread initiates 2 more threads. One reads data on sockets and other logs the data in file.

    Now i want that the primary thread should be capable of handling window messages like WM_CLOSE or minimize/maximize. If i am able to capture these messages i can gracefully exit my secondary threads and clean up memory allocated and close all open threads.

    I want to know how can i capture the messages in console window program when user clicks on close/minimize/maximize button.

    Kavitesh Singh.

  2. #2
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: Multithreaded Console application similar to windows Application.

    Quote Originally Posted by kavitesh
    Now i want that the primary thread should be capable of handling window messages like WM_CLOSE or minimize/maximize. If i am able to capture these messages i can gracefully exit my secondary threads and clean up memory allocated and close all open threads.
    SetConsoleCtrlHandler, signal, and atexit pop to mind.

  3. #3
    Join Date
    Mar 2006
    Posts
    12

    Re: Multithreaded Console application similar to windows Application.

    Well i tried
    atexit()
    but then it only works if application reaches normal end.

    If application is doing something and i press [x] button it does not execute.

    I wanted any kind of termination should be handled and done some clean up operation and then exit.
    Kavitesh Singh

  4. #4
    Join Date
    Jun 2006
    Location
    M31
    Posts
    885

    Re: Multithreaded Console application similar to windows Application.

    Quote Originally Posted by kavitesh
    I wanted any kind of termination should be handled and done some clean up operation and then exit.
    So handle CTRL_CLOSE_EVENT (via SCCH) and whatever else you may need.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured