joe_pool_is
August 22nd, 2005, 12:40 PM
I have developed a class that updates our software when an update is detected on our FTP site. My objective is to make the interface as simple as possible so that other developers do not need to know anything about how threads work in order to use it. I have, therefore, designed a simple public method as follows:
int cFTP::FtpStart(bool bThread);
where bThread equal to false disables threading and true enables threading.
My class begins by FTPing into our company's server and downloading a small (~200 byte) text file containing the software upgrade version. If the upgrade is newer than what they are running, a MessageBox is displayed, asking permission to download it. (Updates could range from 3 - 20 MB, and our customers could have slow connections. So this update could potentially take a long time!)
As long as bThread is set to false, the class works. It is when I set this value to true that I experience problems, and it is certainly in the unique way that I have implemented _beginthread. I am hoping that someone will be able to see why my technique can not be used, and suggest ideas to fix it.
Here is the (greatly simplified) code:void kickOff(void* pObj)
{
((cFTP*)pObj)->FtpStart(false);
}
int cFTP::FtpStart(bool bThread)
{
if (bThread == true)
{
void* pObject;
pObject = (void*)this;
_beginthread(kickOff, 4096, pObject);
return 1;
}
// This section is always called
DownloadTextFile();
if (UpdateAvailable() == true)
{
if (MessageBox(NULL, "An update is available. Download it?",
"AutoUpdate", MB_YESNO) == IDNO)
{
return 0;
}
DownloadSetupFile();
}
return 0;
}
I was unable to pass my class method FtpStart to _beginthread, so I devised a "work around" by calling kickOff to do it for me. Apparently, I have created something that I was not supposed to, but I can not think of a better way of doing it. The compiler does not see any errors, but the program becomes non-responsive when the MessageBox returns IDYES (even an IDNO response causes no issues). I would certainly appreciate any help.
Regards,
Joe
int cFTP::FtpStart(bool bThread);
where bThread equal to false disables threading and true enables threading.
My class begins by FTPing into our company's server and downloading a small (~200 byte) text file containing the software upgrade version. If the upgrade is newer than what they are running, a MessageBox is displayed, asking permission to download it. (Updates could range from 3 - 20 MB, and our customers could have slow connections. So this update could potentially take a long time!)
As long as bThread is set to false, the class works. It is when I set this value to true that I experience problems, and it is certainly in the unique way that I have implemented _beginthread. I am hoping that someone will be able to see why my technique can not be used, and suggest ideas to fix it.
Here is the (greatly simplified) code:void kickOff(void* pObj)
{
((cFTP*)pObj)->FtpStart(false);
}
int cFTP::FtpStart(bool bThread)
{
if (bThread == true)
{
void* pObject;
pObject = (void*)this;
_beginthread(kickOff, 4096, pObject);
return 1;
}
// This section is always called
DownloadTextFile();
if (UpdateAvailable() == true)
{
if (MessageBox(NULL, "An update is available. Download it?",
"AutoUpdate", MB_YESNO) == IDNO)
{
return 0;
}
DownloadSetupFile();
}
return 0;
}
I was unable to pass my class method FtpStart to _beginthread, so I devised a "work around" by calling kickOff to do it for me. Apparently, I have created something that I was not supposed to, but I can not think of a better way of doing it. The compiler does not see any errors, but the program becomes non-responsive when the MessageBox returns IDYES (even an IDNO response causes no issues). I would certainly appreciate any help.
Regards,
Joe