Click here to Skip to main content
15,889,724 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Someone, Anyone Help Plz Pin
Gary R. Wheeler21-Feb-04 13:05
Gary R. Wheeler21-Feb-04 13:05 
GeneralNeed help with restaring a thread Pin
Aralguppe21-Feb-04 8:23
Aralguppe21-Feb-04 8:23 
GeneralRe: Need help with restaring a thread Pin
Neville Franks21-Feb-04 9:50
Neville Franks21-Feb-04 9:50 
GeneralRe: Need help with restaring a thread Pin
Tim Smith21-Feb-04 12:10
Tim Smith21-Feb-04 12:10 
GeneralRe: Need help with restaring a thread Pin
Neville Franks21-Feb-04 20:01
Neville Franks21-Feb-04 20:01 
GeneralRe: Need help with restaring a thread Pin
Aralguppe22-Feb-04 7:09
Aralguppe22-Feb-04 7:09 
GeneralRe: Need help with restaring a thread Pin
Neville Franks22-Feb-04 9:24
Neville Franks22-Feb-04 9:24 
GeneralRe: Need help with restaring a thread Pin
Gary R. Wheeler21-Feb-04 12:21
Gary R. Wheeler21-Feb-04 12:21 
Like Neville said, the key is to ensure that your thread never exits in the first place. One simple way to do that is to encapsulate the body of the thread in a try/catch block:
UINT ThreadFunction(LPVOID parameter)
{
    for ( ; ; ) {
        try {
            // here's the code that can cause an exit
        }
        catch (...) {
            // here's where you handle failures
        }
    }
    return 0;
}
The catch (...) block catches all exceptions. Putting the try/catch block inside the for( ; ; ) loop creates the 'automatic restart' effect you are looking for.

Note that the catch (...) is typically considered to be poor practice. Too many programmers use it rather than catching the exact exceptions that they are interested in, which means error handling stops at that spot. In your case it would be a valid usage, since the catch (...) occurs at the outer edge of the executable code for the thread.


Software Zen: delete this;
GeneralRe: Need help with restaring a thread Pin
Aralguppe22-Feb-04 6:40
Aralguppe22-Feb-04 6:40 
GeneralRe: Need help with restaring a thread Pin
Gary R. Wheeler22-Feb-04 15:43
Gary R. Wheeler22-Feb-04 15:43 
Generalrotate function Pin
Cuu21-Feb-04 7:55
Cuu21-Feb-04 7:55 
GeneralRe: rotate function Pin
alex.barylski21-Feb-04 11:16
alex.barylski21-Feb-04 11:16 
GeneralRe: rotate function Pin
Cuu21-Feb-04 19:32
Cuu21-Feb-04 19:32 
GeneralRe: rotate function Pin
Cuu22-Feb-04 4:23
Cuu22-Feb-04 4:23 
GeneralVisual C++ 6 Syntax Highlighting Pin
Archer28221-Feb-04 7:11
Archer28221-Feb-04 7:11 
GeneralRe: Visual C++ 6 Syntax Highlighting Pin
Ravi Bhavnani21-Feb-04 8:07
professionalRavi Bhavnani21-Feb-04 8:07 
GeneralRe: Visual C++ 6 Syntax Highlighting Pin
Archer28221-Feb-04 8:13
Archer28221-Feb-04 8:13 
GeneralRe: Visual C++ 6 Syntax Highlighting Pin
Ravi Bhavnani21-Feb-04 8:22
professionalRavi Bhavnani21-Feb-04 8:22 
GeneralRe: Visual C++ 6 Syntax Highlighting Pin
Archer28221-Feb-04 8:26
Archer28221-Feb-04 8:26 
GeneralRe: Visual C++ 6 Syntax Highlighting Pin
Ravi Bhavnani21-Feb-04 8:41
professionalRavi Bhavnani21-Feb-04 8:41 
GeneralRe: Visual C++ 6 Syntax Highlighting Pin
Archer28221-Feb-04 8:44
Archer28221-Feb-04 8:44 
GeneralRe: Visual C++ 6 Syntax Highlighting Pin
Ravi Bhavnani21-Feb-04 8:49
professionalRavi Bhavnani21-Feb-04 8:49 
Generalwindows program in background and simulate keyboard Pin
Ylis21-Feb-04 5:41
Ylis21-Feb-04 5:41 
GeneralRe: windows program in background and simulate keyboard Pin
Prakash Nadar21-Feb-04 5:46
Prakash Nadar21-Feb-04 5:46 
GeneralRe: windows program in background and simulate keyboard Pin
Ylis21-Feb-04 6:43
Ylis21-Feb-04 6:43 

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.