thread question
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.
[733 byte] By [
cybertank] at [2007-11-18 17:35:24]

# 1 Re: thread question
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.
# 2 Re: thread question
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 at 2007-11-9 13:56:49 >

# 6 Re: thread question
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.