Click to See Complete Forum and Search --> : thread question
cybertank
March 6th, 2004, 07:39 AM
I execute a function as a thread, like so:
AfxBeginThread((AFX_THREADPROC)CVersionChecker::CheckForUpdate, NULL);
where CVersionChecker::CheckForUpdate is a static function that checks if there are updates available for my application.
The issue I'm grappling with is that if there are updates available, I'd like to close my main application, and retrieve the updates. Is it possible to have a thread live longer than the application that instantiated it?
At this point, if I kill the main app dialog the thread dies with it. I kill the main app by passing a pointer to it to the thread, so that it can do parentDialog->EndDialog(0);
Any tips would be greatly appreciated.
OReubens
March 6th, 2004, 07:49 AM
A (worker)thread can be active longer than it's main GUI thread, but if you need the app to close (to replace the .exe file), then all threads will need to be ended as well. The process will remain active in memory for as long as it has running threads.
Updating features like this are usually solved by launching a separate update APP which will take care of replacing the active .exe/.dll files in use by the application.
Mick
March 6th, 2004, 07:49 AM
I guess it depends on what you are updating. Your execuatables? A data file?
You could create a service that runs in the background and checks for updates.
You could just call CreateProcess(...) on a update executable and exit your main app and allow the updater to pull down the updates.
etc etc...
Mick
March 6th, 2004, 07:52 AM
We need a 'you owe me a beer rule' when the same thing is posted in the same minute :D
OReubens
March 6th, 2004, 11:41 AM
Well, then I guess we both owe eachother a beer ;-)
Andreas Masur
March 6th, 2004, 12:38 PM
[Moved thread]
Sam Hobbs
March 7th, 2004, 06:48 PM
Many developers, probably most, use a Windows user name that has full Administrator privileges. You might think I am wacko for saying that, if it seems off-topic. However it is highly relevant.
I do use a user name without full Administrator privileges for most everything I do in Windows. This is probably more consistent with the environment for most employees in a corporate environment. It is quite irritating for me when software says I need to update something when I am using my regular user name but then I have to say I don't want to update. I can't update until I switch to my Administrator account, but when I switch, then I have to hunt fot the update.
So you should consider the situation where the updates must be done later, and perhaps even by someone other than the regular user. I could be more specific, but I think you get the idea.
cybertank
March 8th, 2004, 07:31 AM
Thanks for all the tips. It all makes sense. I will have to have a helper app which kills them main app and starts the update. Also, thanks for the tips about user issues.
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.