Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have developed a class that updates our customer's software when a newer version 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

Posted

I'm guessing c++ instead of the regular c#/vb.net we see here ;).

 

All the 'fun' threading / timer have problems taking class methods, and your workaround is the same trick I use myself as well ;).

 

Are you sure the msgbox isnt the cause of the problem? Does the code work correctly if you remove it and just assume the user selects yes. If it does work without, it could be the good old 'dont do gui stuff on the wrong thread' problem, using C++ does not invalidate that rule :p.

 

If that doesnt fix it, we'd need some more info on the DownloadSetupFile method I think.

Can't you debug the problem? Just put a breakpoint on the DownloadSetupFile method to see if the program actually reaches it. Visual studio has no problems debugging multithreaded applications, the only problem is the human brain that can't cope with thread context switches in a debugger (where you press F10 to advance a single line and end up in a completely different file, only figuring out a thread context switch happened after 10 minutes of staring at your screen :D).

Nothing is as illusive as 'the last bug'.
Posted

Wile,

 

This certainly has me re-thinking my whole strategy. Give me some time to look into this, and I might post again later if I can narrow down what the problems are stemming from after a little reworking.

 

FYI: C++ is correct! What's *really* going to make you wonder what I am doing here is the fact that I am writing this in Borland Builder 6. Well, this board has more activity (i.e. faster responses) than anything the Borland people have. But wait! There's more: Ya know those DownloadTextFile() and DownloadSetupFile() functions? Those were written to help simplify code for display purposes. The actual functions are in fact only one function:

 

bool Download(char* downloadFile, char* saveAs);

 

Still more details: The Download() function is part of an old component called FastNet by the company NetMasters. Our company wants to use this because they already own it and they say it works with Borland, Linux, and maybe others. If I had posted all of that information before, no one would have responded! Funny how people work, huh? :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...