Discussion:
System locks up until InternetOpenURL call completes
(too old to reply)
Dan
2005-09-30 13:34:19 UTC
Permalink
I have an app that a lot of people use. It pulls down HTML from the
Internet using the following InternetOpenURL call in VB:

lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)

If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If

The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
Reymarx Gereda
2005-10-18 23:41:13 UTC
Permalink
Hi Dan,

The behavior occurs because you're calling the WinInet API in Synchronous
mode.

In order for your application not to block, you'll have to call
InternetOpenUrl in Asynchronous mode.

You can find some information about how to use WinInet in async mode within
VB, here:

http://support.microsoft.com/default.aspx?scid=kb;en-us;189850

Hope this helps you.


Reymarx [MSFT]
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
Dan
2005-10-26 12:50:45 UTC
Permalink
I really don't want to switch to asynchronous calls. And it still
doesn't explain why it would lock up some computers and not others.
Post by Reymarx Gereda
Hi Dan,
The behavior occurs because you're calling the WinInet API in Synchronous
mode.
In order for your application not to block, you'll have to call
InternetOpenUrl in Asynchronous mode.
You can find some information about how to use WinInet in async mode within
http://support.microsoft.com/default.aspx?scid=kb;en-us;189850
Hope this helps you.
Reymarx [MSFT]
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
dwiz
2005-11-08 11:54:15 UTC
Permalink
You mean your app hangs?

The reason your app hangs is that the openurl method will just continue to
try to connect to the server. So if the server is down, or can't connect for
some other reason, your program will just sits there waiting. I have this
same problem with one of my apps and have not found a good solution. What
you can do is put this code in a seperate thread and set a timer to kill the
thread after a short time.

If you find a better way let me know.

DW.
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
Paul Baker
2005-11-08 14:20:49 UTC
Permalink
Also, if you use InternetConnect, HttpOpenRequest, HttpSendRequest, etc...
instead of InternetOpenURL, you can cause the Http* function to abort and
return immediately simply by closing the HINTERNET handle of the request.

Paul
Post by dwiz
You mean your app hangs?
The reason your app hangs is that the openurl method will just continue to
try to connect to the server. So if the server is down, or can't connect
for some other reason, your program will just sits there waiting. I have
this same problem with one of my apps and have not found a good solution.
What you can do is put this code in a seperate thread and set a timer to
kill the thread after a short time.
If you find a better way let me know.
DW.
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
Paul Baker
2005-11-08 14:28:24 UTC
Permalink
Or, you can close the HINTERNET of the session with any of these calls,
including InternetOpenUrl. Again, this will abort the operation, the
function will return and your thread can exit.

Paul
Post by Paul Baker
Also, if you use InternetConnect, HttpOpenRequest, HttpSendRequest, etc...
instead of InternetOpenURL, you can cause the Http* function to abort and
return immediately simply by closing the HINTERNET handle of the request.
Paul
Post by dwiz
You mean your app hangs?
The reason your app hangs is that the openurl method will just continue
to try to connect to the server. So if the server is down, or can't
connect for some other reason, your program will just sits there waiting.
I have this same problem with one of my apps and have not found a good
solution. What you can do is put this code in a seperate thread and set a
timer to kill the thread after a short time.
If you find a better way let me know.
DW.
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
dwiz
2005-11-08 17:27:35 UTC
Permalink
doh!

Here's the easiest solution:
CInternetSession session;

session.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, 8000); // timout after 8
secs if server not responding

this is for VC++2003 but there should be a similar option in VB.

I've scoured the net for this solution but nobody ever suggested it.
Everyone said they had tried setting the

INTERNET_OPTION_CONNECT_TIMEOUT option to no avail but the one above works
fine.

DW.
Post by Reymarx Gereda
Hi Dan,
The behavior occurs because you're calling the WinInet API in Synchronous
mode.
In order for your application not to block, you'll have to call
InternetOpenUrl in Asynchronous mode.
You can find some information about how to use WinInet in async mode
http://support.microsoft.com/default.aspx?scid=kb;en-us;189850
Hope this helps you.
Reymarx [MSFT]
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
Paul Baker
2005-11-08 22:21:53 UTC
Permalink
Well, yes, this limits the timeout to 8 seconds, but what does it really
achieve?

1. It is a little shorter than the default so, when latency is high, you
will on occasion fail to connect when you should be able to.
2. It will still stop responding, just not for as long.

Imagine if this were the behaviour of Internet Explorer! Internet Explorer
has it right. It uses threads and can respond to user input at any time,
aborting as needed.

Paul
Post by dwiz
doh!
CInternetSession session;
session.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, 8000); // timout after
8 secs if server not responding
this is for VC++2003 but there should be a similar option in VB.
I've scoured the net for this solution but nobody ever suggested it.
Everyone said they had tried setting the
INTERNET_OPTION_CONNECT_TIMEOUT option to no avail but the one above works
fine.
DW.
Post by Reymarx Gereda
Hi Dan,
The behavior occurs because you're calling the WinInet API in Synchronous
mode.
In order for your application not to block, you'll have to call
InternetOpenUrl in Asynchronous mode.
You can find some information about how to use WinInet in async mode
http://support.microsoft.com/default.aspx?scid=kb;en-us;189850
Hope this helps you.
Reymarx [MSFT]
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
dwiz
2005-11-09 16:36:36 UTC
Permalink
What it achieves is the app won't wait indefinitely. Actually it's a lot
shorter time than the default because the default is infinite according to
the MSDN docs.
Anyway, I agree the call will give up even if the server is available but
running slow.
It's best to allow the user to quit when they like as you suggested.
I've done this as you originally pointed out by closing the internet handle
using the
InternetCloseHandle(HINTERNET h) api.

This works beautifully so thanks for that :)

DW.
Post by Paul Baker
Well, yes, this limits the timeout to 8 seconds, but what does it really
achieve?
1. It is a little shorter than the default so, when latency is high, you
will on occasion fail to connect when you should be able to.
2. It will still stop responding, just not for as long.
Imagine if this were the behaviour of Internet Explorer! Internet Explorer
has it right. It uses threads and can respond to user input at any time,
aborting as needed.
Paul
Post by dwiz
doh!
CInternetSession session;
session.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, 8000); // timout
after 8 secs if server not responding
this is for VC++2003 but there should be a similar option in VB.
I've scoured the net for this solution but nobody ever suggested it.
Everyone said they had tried setting the
INTERNET_OPTION_CONNECT_TIMEOUT option to no avail but the one above
works fine.
DW.
Post by Reymarx Gereda
Hi Dan,
The behavior occurs because you're calling the WinInet API in
Synchronous mode.
In order for your application not to block, you'll have to call
InternetOpenUrl in Asynchronous mode.
You can find some information about how to use WinInet in async mode
http://support.microsoft.com/default.aspx?scid=kb;en-us;189850
Hope this helps you.
Reymarx [MSFT]
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
Paul Baker
2005-11-10 15:53:58 UTC
Permalink
You're welcome.

I don't know where you saw that the timeout is infinite, it is not.

Paul
Post by dwiz
What it achieves is the app won't wait indefinitely. Actually it's a lot
shorter time than the default because the default is infinite according to
the MSDN docs.
Anyway, I agree the call will give up even if the server is available but
running slow.
It's best to allow the user to quit when they like as you suggested.
I've done this as you originally pointed out by closing the internet
handle using the
InternetCloseHandle(HINTERNET h) api.
This works beautifully so thanks for that :)
DW.
Post by Paul Baker
Well, yes, this limits the timeout to 8 seconds, but what does it really
achieve?
1. It is a little shorter than the default so, when latency is high, you
will on occasion fail to connect when you should be able to.
2. It will still stop responding, just not for as long.
Imagine if this were the behaviour of Internet Explorer! Internet
Explorer has it right. It uses threads and can respond to user input at
any time, aborting as needed.
Paul
Post by dwiz
doh!
CInternetSession session;
session.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, 8000); // timout
after 8 secs if server not responding
this is for VC++2003 but there should be a similar option in VB.
I've scoured the net for this solution but nobody ever suggested it.
Everyone said they had tried setting the
INTERNET_OPTION_CONNECT_TIMEOUT option to no avail but the one above
works fine.
DW.
Post by Reymarx Gereda
Hi Dan,
The behavior occurs because you're calling the WinInet API in
Synchronous mode.
In order for your application not to block, you'll have to call
InternetOpenUrl in Asynchronous mode.
You can find some information about how to use WinInet in async mode
http://support.microsoft.com/default.aspx?scid=kb;en-us;189850
Hope this helps you.
Reymarx [MSFT]
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
mf.zhang
2005-11-14 18:17:50 UTC
Permalink
where can i find some async mode sample code using WinInet class (HTTP
post)?

thanks

John
Post by Reymarx Gereda
Hi Dan,
The behavior occurs because you're calling the WinInet API in Synchronous
mode.
In order for your application not to block, you'll have to call
InternetOpenUrl in Asynchronous mode.
You can find some information about how to use WinInet in async mode
http://support.microsoft.com/default.aspx?scid=kb;en-us;189850
Hope this helps you.
Reymarx [MSFT]
Post by Dan
I have an app that a lot of people use. It pulls down HTML from the
lngOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
If lngOpen <> 0 Then
lngOpenURL = InternetOpenUrl(lngOpen, strURL, vbNullString, 0, _
INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_COOKIES Or _
INTERNET_FLAG_NO_CACHE_WRITE, 0)
End If
The above works fine on my test machines as well as on about 99% of my
users but occasionally I have one report that when it is pulling
information from the Internet their system becomes unresponsive until
the call is completed. I've never been able to reproduct this or
determine why this might be happening. Does anyone have any ideas what
could be causing the systems to lock up?
Loading...