suggestions for a wxDownloadThread
Francesco Montorsi
f18m_cpp217828 at yahoo.it
Sun Sep 3 15:06:34 PDT 2006
Hi all,
I'm not expert at all with multi-threading programming but I need
to write a wxThread-derived class to handle downloads of stuff from WWW.
I possibly want this class to have the following features:
1) fire-and-forget: since the download could be launched from one
function and then handled by others I'd like to have no cleanup to do at
all, thus I'd be in favour of a wxTHREAD_DETACHED
2) events: the download should send events to a wxEvtHandler object
about progresses done and completion.
and here comes the problem:
3) I want to be able to eventually abort a download once it has started
Can I use a detached thread and still be able to get feature #3?
AFAIU a detached thread should never be tested:
myDetachedThread *p = new myDetachedThread;
p->GetSomething(); // ERROR! the thread could not exist anymore!!!
right?
So, how can I communicate from the main thread to a detached thread ?
Detached thread -> main thread communication can be done through events
but I wonder how can I communicate from the main thread the "abort"
command to the detached thread...
any idea ?
am I forced to use a joinable thread ?
Thanks,
Francesco
BTW: I think that a wxDownloadThread with the 3 features above should
really be part of wxWidgets as anyone using a GUI and in need to
download a file needs to wrap wxURL::GetInputStream in a separate thread
to avoid blocking the application. Maybe I could submit it as a patch to
wx when it's done?
More information about the wx-users
mailing list