Click here to get back home

Asynch wininet - Threaded or not?

 HomeNewsGroups | Search | About
 microsoft.public.smartphone.developer    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Asynch wininet - Threaded or not? Fred 02-01-2006
Posted by Fred on February 1, 2006, 9:51 am
Please log in for more thread options
Hi,

If I use asynch Wininet is there any purpose in hiving of the Wininet calls
into separate threads and the extra complication which ensues? As from what
I can see the system starts a separate thread implicitly for the asynch
calls anyway.
The reason I ask is I imagine the thread switching might ensure that the UI
remains responsive - plus there may be other issues you can enlighten me
with.

My application is "real-time" and will be applied to a Pocket PC/Smartphone
as well as WinXP so I need the quickest/most efficient functionality
possible.

Also the UI response must be as fast as possible.

The application basically "GET"s a website for info then issues occasional -
through crucial "POST"s prompted by the user via the UI.

Both the GETS and POSTS must be carried out as close to real-time as
possible.

TIA




Posted by Scherbina Vladimir on February 1, 2006, 4:27 pm
Please log in for more thread options
Hello, Fred.

> Hi,
>
> If I use asynch Wininet is there any purpose in hiving of the Wininet
> calls
> into separate threads and the extra complication which ensues? As from
> what
> I can see the system starts a separate thread implicitly for the asynch
> calls anyway.
> The reason I ask is I imagine the thread switching might ensure that the
> UI
> remains responsive - plus there may be other issues you can enlighten me
> with.
>
> My application is "real-time" and will be applied to a Pocket
> PC/Smartphone
> as well as WinXP so I need the quickest/most efficient functionality
> possible.
>
> Also the UI response must be as fast as possible.
>
> The application basically "GET"s a website for info then issues
> occasional -
> through crucial "POST"s prompted by the user via the UI.
>
> Both the GETS and POSTS must be carried out as close to real-time as
> possible.
> TIA

Even if you use wininet synchronously system might create additional threads
and you cannot control this behavour. So putting async. calls into separate
thread is useless.

You may achieve the fastest result by creating the "worker" thread that
waits on some object (for instance, event) and when GUI thread is going to
make a GET or POST it sets the event and allows worker thread to accomplish
the actual work using syncronous wininet calls.

--
Vladimir



Posted by Scherbina Vladimir on February 2, 2006, 12:33 am
Please log in for more thread options
> Hi,
>
> I have built a related application which uses synchronous Wininet. However
> I
> have never worked out how to terminate a single thread if it hangs. The MS
> workarounds to the wininet bug seem to terminate all active Wininet calls.

Documentation states that if you have a thread that is reading or writing
something to/from stream using HINTERNET handle you can close that handle on
another thread using InternetCloseHandle. So if you have you "worker"
sending POST or GET via HttpSendRequest closing HINTERNET handle that is
used in HttpSendRequest will cancel sending request.

--
Vladimir



Posted by Fred on February 2, 2006, 6:31 am
Please log in for more thread options

> > Hi,
> >
> > I have built a related application which uses synchronous Wininet.
However
> > I
> > have never worked out how to terminate a single thread if it hangs. The
MS
> > workarounds to the wininet bug seem to terminate all active Wininet
calls.
>
> Documentation states that if you have a thread that is reading or writing
> something to/from stream using HINTERNET handle you can close that handle
on
> another thread using InternetCloseHandle. So if you have you "worker"
> sending POST or GET via HttpSendRequest closing HINTERNET handle that is
> used in HttpSendRequest will cancel sending request.

I have read that the cancelling thread MS fix,
http://support.microsoft.com/kb/224318/EN-US/ will cancell all threads
currently accessing the Internet - although I can't find the original
reference which details this.

I have also come across this assertion:

"The async mode is most suited to applications which must be single threaded
and stay responsive to the end user and in extreme performance and memory
sensitive situations"

Although that was in a very old book :)





Posted by Fred on February 2, 2006, 2:40 pm
Please log in for more thread options

> Fred,
>
> Let's discuss what your old book says:
>
> "The async mode is most suited to applications which must be single
threaded
> and stay responsive to the end user and in extreme performance and memory
> sensitive situations"
>
> This is technically true, but don't be misled by it!
>
> If an application must be single threaded, then synchronous mode by
> definition will prevent it from returning to the message loop until it is
> done. However, there is no such application in practice. Who's stopping
you
> from using multiple threads? Nobody! Only your own lack of knowledge about
> multithreaded programming, perhaps.

Yes as far as synchronous/asynchronous Wininet and multithreading is
concerned.
I have written a pretty complicated prog with a thread pool and synchronous
Wininet and it works - but I'm still not happy about cancelling threads when
we have a timed-out block.

> The rest of it is presumably talking about the expense of creating a
thread.
> It takes a little time and it allocates some memory (the largest part of
> which is the stack). However, these are not really relevant issues for
most
> applications. You're not going to be downloading thousands of web pages at
> once are you?

What is the extra complexity involved in writing asynch wininet?

MS's asyncdemo doesn't look too bad

http://msdn.microsoft.com/library/en-us/wininet/wininet/calling_wininet_functions_asynchronously.asp







Similar ThreadsPosted
Re: Asynch wininet - Threaded or not? February 2, 2006, 2:45 pm
SSL with WinINet April 16, 2008, 4:30 pm
WinInet problem August 1, 2005, 1:44 am
Can wininet functions trigger CM to auto-establish a GPRS connecti June 11, 2005, 10:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap