Click to See Complete Forum and Search --> : Thread Program: From console app to Windows System Tray app


novice123
March 18th, 2006, 12:26 PM
Hi,

I have multi-thread program as a console application. The program runs fine as it is. But i am trying to convert it to windows application with system tray icon so that in the system tray i have an icon and i will be able start and stop gracefully.

I am able to start the program with threads, but when i want to stop the program , i cannot do it. After the program has started i am unable to right click on the tray-icon, so that i can stop.

Currently in Console application i have 5 threads.
1. Main-thread . Main thread starts 2 threads, threadFunc1 and threadFunc2 . These 2 threads one thread each for processing.

I guess when i trying to stop, i don't know which thread is active. I tried ExitThread -- which would basically kill every thing, but this does not seem to work.

I tried TerminateThread, terminating each thread , but even that does not help.

Can some one has done this similar stuff, before can you please throw some light.

I am using Create thread for creating threads. Do i need to change the CreateThread to AfxBeginThread ?

Any help is appreciated and thanks in advance....

thank you

kuphryn
March 20th, 2006, 03:18 PM
Describe the threads. Loop?

Kuphryn

zerver
March 22nd, 2006, 11:32 AM
I don't recommend using it, but the magic

TerminateProcess(GetCurrentProcess());

always works for me :wave:

Siddhartha
March 27th, 2006, 12:10 PM
When the user selects the option to close your application - set an event.

Inside the threads, poll the Event using WaitForSingleObject, like this -
if (WaitForSingleObject (hEventHandle, 0) == WAIT_OBJECT_0)
; // Exit thread (return from it) A complete explanation of a similar scenario is here (http://www.codeguru.com/forum/showpost.php?p=1327913&postcount=4).