Click here to Skip to main content
13,357,438 members (67,686 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 3 Mar 2000

PStat v1.2 - Threading Framework

, 3 Mar 2000
Rate this:
Please Sign up or sign in to vote.
A Freeware generalized framework for executing a lengthy operation in a thread.
  • Download source files - 20 Kb
  • Introduction

    API Reference
    Contacting the Author

    Welcome to pstat, a freeware generalized framework for executing a lengthy operation in a thread. Feedback is provided by a progress dialog which can optionally be cancelled. Included is a simple dialog based application which shows how to use it. The program demonstrates the difference threading can make by showing the difference with and without pstat. Try using the without pstat option from the test program and tab to another program, when you tab back you will notice that it's window is white meaning that it is not responding to any window messages. Now try the same with pstat. Notice the difference.

    The sample application included with PStat allows you to calculate the 100,000th prime number both with and without pstat. When executed without pstat you will notice that the sample application becomes totally hung and fails to respond to window messages. With pstat you have no such problems.

    When executed with pstat, while your function is being executed a progress dialog will be displayed as:

    Sample Image

    If you want to allow the user to cancel the operation during your function then the progress dialog can be displayed with a cancel button as:

    Sample Image


    • Simple single function to call to get your code to run in the context of another thread.
    • All the code is fully UNICODE compliant.
    • Compiles cleanly at warning level 4.
    • Time remaining static is automatically calculated.
    • A simple test app is included.


    v1.0 (27th March 1997)
    • Initially created.

    v1.1 (18th February 1998)

    • Fixed a bug where the worker thread was trying to close a dialog before it was created. A CEvent member of CProgressThreadDlg now protects this. Also removed the usual appwizard comments from the demo program.

    v1.2 (8th November 1998)

    • Added an option to confirm cancel by means of a message box.
    • General tidy up of the code.
    • Inclusion of VC 5 workspace files now as standard.
    • All code now compiles cleanly at warning level 4.
    • Code now supports UNICODE and build configurations are now provided.
    • HTML help file now provided.


    To use pstat in your applications simply include pstat.cpp in your project and #include "pstat.h" in whichever module wants to access it.

    API Reference

    PStat is made up of the single function as follows:


    BOOL ExecuteFunctionWithProgressDialog(FUNCTION_WITH_PROGRESS* pfnFunction, const CString& sProgressTitle, void* pData = NULL, DWORD dwFlags = 0, const CString& sConfirmPrompt = _T(""), int nPriority = THREAD_PRIORITY_NORMAL, CWnd* pWndParent = NULL);

    Return Value:
    TRUE if the function was successfully executed otherwise FALSE i.e. the dialog was cancelled or some other error occurred.


    • pfnFunction -- Your actual function to call to get your function to work in a separate thread with a progress dialog being displayed while it is executing. pfnFunction should have the following definition:
      typedef ULONG (FUNCTION_WITH_PROGRESS)(void* pData, CProgressThreadDlg* pProgressDlg);
    • sProgressTitle -- The title that should appear on the progress dialog while your function is executing.
    • pData -- Any user defined data that your function will be called with. Similar to the way threads give you a single LPVOID parameter.
    • dwFlags -- Bitwise compliment of flags to customize how the function will be executed. Currently only PSTAT_CANCEL and PSTAT_CONFIRMCANCEL are available which will display a cancel button on the progress dialog. PSTAT_CANCEL will allow the operation to be cancelled while PSTAT_CONFIRMCANCEL will prompt when a request for cancel is made by means of a message box.
    • sConfirmPrompt -- Message text to display in confirm cancel message if PSTAT_CONFIRMCANCEL flag is used.
    • nPriority -- The thread priority of the thread pfnFunction will execute at. See Win32 help for further details if unclear.
    • pWndParent -- The window which the progress dialog will use as its parent.

    To see how your pfnFunction should be coded, have a look at the CalculatePrimeNumbers() in pstattestdlg.cpp. As your function will be executed in the context of another MFC thread, you will need to be aware of the usual synchronisation and access issues which come with multi-threaded MFC applications.

    Contacting the Author

    PJ Naughter
    8th November 1998


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    PJ Naughter
    United States United States
    No Biography provided

    You may also be interested in...

    Comments and Discussions

    Generalmemory leak! Pin
    adam smith10-Jul-01 20:45
    memberadam smith10-Jul-01 20:45 
    GeneralRe: memory leak! Pin
    pjnaughter3-Feb-03 11:05
    memberpjnaughter3-Feb-03 11:05 
    GeneralFix for memory error Pin
    Patrick Koorevaar28-May-01 2:35
    memberPatrick Koorevaar28-May-01 2:35 
    GeneralRe: Fix for memory error Pin
    pjnaughter3-Feb-03 11:09
    memberpjnaughter3-Feb-03 11:09 
    GeneralFix for possible A/V Pin
    Jeff Miller18-Apr-00 12:48
    sussJeff Miller18-Apr-00 12:48 
    GeneralRe: Fix for possible A/V Pin
    PJ Naughter18-Apr-00 12:56
    sussPJ Naughter18-Apr-00 12:56 
    Generalit's good,but i want not to wait the child thread to finish. Pin
    bunhou8-Apr-00 23:44
    sussbunhou8-Apr-00 23:44 
    GeneralRe: it's good,but i want not to wait the child thread to finish. Pin
    PJ Naughter9-Apr-00 6:58
    sussPJ Naughter9-Apr-00 6:58 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web01 | 2.8.180111.1 | Last Updated 4 Mar 2000
    Article Copyright 2000 by PJ Naughter
    Everything else Copyright © CodeProject, 1999-2018
    Layout: fixed | fluid