Scherbina
Fri Feb 03 06:59:31 CST 2006
Hello, Fred.
"Fred" <not@home.com> wrote in message
news:Htmdnc13puaf2n7eRVnygQ@pipex.net...
>
> The demo
http://support.microsoft.com/kb/224318/EN-US/
>
> uses the handle for InternetOpen () to close the thread if the thread is
> hanging. So if I have multiple connections (threads) from the one
> InternetOpen () (which is the recommended technique) then any wininet
> activity must surely be terminated on *all* these threads - which is not
> what I want.
>
> Now documentation states:
>
> "The application can make any number of calls to InternetOpen, though a
> single call is normally sufficient. "
>
> So to stop one hanging thread then I would have to have a separate
> InternetOpen for each thread and then a separate Internetconnect() too -
> what is the overhead for this? Surely it is more than marginal - and don't
> forget I will be porting to SmartPhone which has nowhere near the
> horsepower
> of a PC.
>
> These above concerns are the issues which prompted my initial post.
>
> So, how do you handle hanging/blocking threads? Terminating them all when
> only one is blocking, say on an InternetReadFile() cannot be the ideal
> solution.
>
> Further can you actual terminate on any blocking wininet function, say if
> InternetReadFile() is blocking or does it only work for Internetconnect?
>
> Thanks
There is no need to make an InternetOpen in all threads - this is a really
overhead. You may call InternetOpen once and use returned handle in all
threads.
Each thread (or thread from the pool) makes InternetConnect using handle
returned by InternetOpen. Most likely your thread would not be blocked by
call of InternetConnect, it might hung when you will make call to
HttpOpenRequest / HttpSendRequst, so to cancel blocking of thread you should
close handle of request(or whatever) it made. Microsofts examples closes
handle returned by InternetOpen, but you may cancel execution closing handle
returned by HttpOpenRequest or simular function.
So, once more:
1. Locate where your thread may hung (InternetReadFile, HttpSendRequest,
etc)
2. Associate HINTERNET handles open by thread with thread's handle.
3. Mark position *what* wininet function is executed in each thread.
4. When thread is hung, read the position - you know what function is
executed, and the handle it uses, simply close it.
--
Vladimir