After the Thread execute the program does not exit as it should ?

Started by Dogim, November 17, 2010, 08:58:51 PM

Previous topic - Next topic

Dogim

Hallo to all and goodnight.
I,m having trouble figuring this one out.
Its  iczelion multithread tutorial number 15 to be exact( attachment included).
I,m not  a champion debugger, but for what i could figure out ,is that  MessageLoop:
    invoke GetMessage,addr msg,0,0,0 ; Retrieves a message from the calling thread's message queue
    or eax,eax
    jz >ExitProgram
    invoke TranslateMessage,addr msg
    invoke DispatchMessage, addr  msg
    jmp <MessageLoop
ExitProgram:
int 3 ; For testing purpose only
    invoke ExitProcess,[msg.wParam]

it looks like the debugger never reaches the int3 instruction and also it never reaches a breakpoint before the exitcode ( on the push ), or on the exitcode api call itself.
I,m missing something, but i can't put my finger on it.
The Thread itself exit with non zero.
Help is much appreciated.
Thank you.


donkey

"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Antariy

Quote from: Dogim on November 17, 2010, 08:58:51 PM

MessageLoop:
    invoke GetMessage,addr msg,0,0,0 ; Retrieves a message from the calling thread's message queue
    or eax,eax
    jz >ExitProgram
    invoke TranslateMessage,addr msg
    invoke DispatchMessage, addr  msg
    jmp <MessageLoop
ExitProgram:
int 3 ; For testing purpose only
    invoke ExitProcess,[msg.wParam]

it looks like the debugger never reaches the int3 instruction and also it never reaches a breakpoint before the exitcode ( on the push ), or on the exitcode api call itself.
I,m missing something, but i can't put my finger on it.
The Thread itself exit with non zero.
Help is much appreciated.
Thank you.

What if change the piece of message loop to:

invoke GetMessage,addr msg,0,0,0 ; Retrieves a message from the calling thread's message queue
    or eax,eax
    jle >ExitProgram <--- CHANGED THIS


This is not help?

Dogim

Quote from: donkey on November 17, 2010, 09:46:43 PM
Executes fine here Vista x86-32
Hi Donkey, it does execute on my Win 7 64 Bits OS, but the primary Thread  does not exit, so in Rad when  try to recompile it, i get can't delete error, a Ctrl Alt Del shows it still running in the background.

donkey

Hi Dogim,

I spoke too soon, the problem with the exit is only present when you use the menu to exit, I was using the close button. You should post a WM_CLOSE message instead of DestroyWindow, DestoryWindow will flush the message queue so you will not receive the NULL return from GetMessage (as far as I have been able to determine).

.kill_and_exit
   invoke PostMessage,WM_CLOSE,0,0
   jmp >.defwindowproc
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Antariy

So, my suggestion about using of "jle >ExitProgram" is fully ignored :P

Dogim

PROBLEM  SOLVED fixed, Thanks Donkey and Antariy   for  the help.

Dogim

Quote from: Antariy on November 17, 2010, 10:16:51 PM
So, my suggestion about using of "jle >ExitProgram" is fully ignored :P

No i did not ignore your fix, but Donkey was so fast with his answer , i didn't get the chance to reply to your answer  :U :bg
I used both fixes  :lol

Antariy

Quote from: Dogim on November 17, 2010, 10:21:38 PM
Quote from: Antariy on November 17, 2010, 10:16:51 PM
So, my suggestion about using of "jle >ExitProgram" is fully ignored :P

No i did not ignore your fix, but Donkey was so fast with his answer , i didn't get the chance to reply to your answer  :U :bg
I used both fixes  :lol

Just using of jle is as rule - if you destroy window, then GetMessage return value less than 0. If WM_QUIT is received, then GetMessage return 0 - JLE check for zero or negative value  :U

Dogim

Quote from: Antariy on November 17, 2010, 10:26:59 PM
Quote from: Dogim on November 17, 2010, 10:21:38 PM
Quote from: Antariy on November 17, 2010, 10:16:51 PM
So, my suggestion about using of "jle >ExitProgram" is fully ignored :P

No i did not ignore your fix, but Donkey was so fast with his answer , i didn't get the chance to reply to your answer  :U :bg
I used both fixes  :lol

Just using of jle is as rule - if you destroy window, then GetMessage return value less than 0. If WM_QUIT is received, then GetMessage return 0 - JLE check for zero or negative value  :U

Hi  Antariy , the jle>ExitProgram  in combination with Destroywindow function, still keeps it running in the background, when i exit using the menu,exit true the menu only works when i send a WM_CLOSE message as Donkey stated in his answer.

Antariy

Quote from: Dogim on November 17, 2010, 10:41:53 PM
Hi  Antariy , the jle>ExitProgram  in combination with Destroywindow function, still keeps it running in the background, when i exit using the menu,exit true the menu only works when i send a WM_CLOSE message as Donkey stated in his answer.

Did not you call PostQuitMessage or SendMessage,hwnd,WM_QUIT,0,0 before DestroyWindow? That must be at this manner.

Dogim

Quote
Did not you call PostQuitMessage or SendMessage,hwnd,WM_QUIT,0,0 before DestroyWindow? That must be at this manner.
.wmfinish
cmp D[uMsg],WM_FINISH
jne >>.defwindowproc
invoke MessageBoxEx,NULL,ADDR szMbString,ADDR szAppName,MB_OK,0
;jmp >.exit -->FIXED
jmp >.defwindowproc

.kill_and_exit
: invoke DestroyWindow,[hWnd]
: jmp >.exit
invoke PostMessage,[hWnd],WM_CLOSE,0,0 -->FIXED
        jmp >.defwindowproc   ---FIXED

The above code works with jle > ExitProgram, I called the destroywindow api at first, but  i discovered that when i processed the WM_FINISH message i was jumping to >.exit, i should continue to DefWinProc here i think.But however, this way the programs exit true the close and also true the menu.

Antariy

Quote from: Dogim on November 17, 2010, 10:59:21 PM
Quote
Did not you call PostQuitMessage or SendMessage,hwnd,WM_QUIT,0,0 before DestroyWindow? That must be at this manner.
.wmfinish
cmp D[uMsg],WM_FINISH
jne >>.defwindowproc
invoke MessageBoxEx,NULL,ADDR szMbString,ADDR szAppName,MB_OK,0
;jmp >.exit -->FIXED
jmp >.defwindowproc

.kill_and_exit
: invoke DestroyWindow,[hWnd]
: jmp >.exit
invoke PostMessage,[hWnd],WM_CLOSE,0,0 -->FIXED
        jmp >.defwindowproc   ---FIXED

The above code works with jle > ExitProgram, I called the destroywindow api at first, but  i discovered that when i processed the WM_FINISH message i was jumping to >.exit, i should continue to DefWinProc here i think.But however, this way the programs exit true the close and also true the menu.

Usual sequence is PostQuitMessage (or sending of WM_QUIT), and after that - DestroyWindow.

You can make reaction for WM_FINISH like this:

invoke SendMessage,[hWnd],WM_CLOSE,0,0
ret


Or something like - sorry, I'm not very familar with GoAsm yet.

Dogim

Quote from: Antariy on November 17, 2010, 11:12:39 PM

Usual sequence is PostQuitMessage (or sending of WM_QUIT), and after that - DestroyWindow.

You can make reaction for WM_FINISH like this:

invoke SendMessage,[hWnd],WM_CLOSE,0,0
ret


Or something like - sorry, I'm not very familar with GoAsm yet.

This Will shutdown the whole program as soon as the secondary Thread stops executing, so if you want to restart the secondary thread again, your gonna have to start the whole program again.

Antariy

Quote from: Dogim on November 17, 2010, 11:27:02 PM
Quote from: Antariy on November 17, 2010, 11:12:39 PM

Usual sequence is PostQuitMessage (or sending of WM_QUIT), and after that - DestroyWindow.

You can make reaction for WM_FINISH like this:

invoke SendMessage,[hWnd],WM_CLOSE,0,0
ret


Or something like - sorry, I'm not very familar with GoAsm yet.

This Will shutdown the whole program as soon as the secondary Thread stops executing, so if you want to restart the secondary thread again, your gonna have to start the whole program again.

Well, I'm not dig into the program itself. I just suggest a sequence of things to close window, you can adapt anything for your needs  :U