Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

My form blocks when i download an html page code. WHY????

Posted on 2004-09-12
8
Medium Priority
?
188 Views
Last Modified: 2010-04-23
Hy,

This is my code. I download the html content of an Web Page and during this my form is not accessible. I can't press any tab's of my tabcontrol, i can't move my form from point x to point y. What should i do to make my form accessible while the code runs.

Dim req As WebRequest = WebRequest.Create(url)
        Dim res As WebResponse = req.GetResponse()
        Dim iTotalBuff As Integer = 0
        Dim Buffer(128) As [Byte]
        Dim stream As Stream = res.GetResponseStream()
        iTotalBuff = stream.Read(Buffer, 0, 128)
        Dim strRes As New StringBuilder("")
        While iTotalBuff <> 0
            Refresh()
            TextBox2.Refresh()
            Refresh()
            strRes.Append(Encoding.ASCII.GetString(Buffer, 0, iTotalBuff))
            Refresh()
            iTotalBuff = stream.Read(Buffer, 0, 128)
            Refresh()
            TextBox2.Refresh()
        End While

Thanks a lot.
0
Comment
Question by:drcyrus3d
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12040391
From the helpfile:

"The GetResponse method provides synchronous access to the WebResponse. For asynchronous access, use the BeginGetResponse and EndGetResponse methods."

Synchronous means the code will stop until the GetResponse call is complete.

There is an example in the help file on how to use these two methods.

Idle_Mind
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12040499
You can always start a new thread using threading and solve this kind of issues.
Put that code part you posted inside a Sub - End Sub. Then call that sub with a new thread.

Sub GetHTML()
        Dim req As WebRequest = WebRequest.Create(url)
        Dim res As WebResponse = req.GetResponse()
        Dim iTotalBuff As Integer = 0
        Dim Buffer(128) As [Byte]
        Dim stream As Stream = res.GetResponseStream()
        iTotalBuff = stream.Read(Buffer, 0, 128)
        Dim strRes As New StringBuilder("")
        While iTotalBuff <> 0
            Refresh()
            TextBox2.Refresh()
            Refresh()
            strRes.Append(Encoding.ASCII.GetString(Buffer, 0, iTotalBuff))
            Refresh()
            iTotalBuff = stream.Read(Buffer, 0, 128)
            Refresh()
            TextBox2.Refresh()
        End While
End Sub
Then create a thread and start it....
            Dim NewProcess As New System.Threading.Thread(AddressOf GetHTML)
            NewProcess.Start()

-Baan
0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 12040521
Idle_mind i like your idea... but i don't have the MSDN. :(((((

Can you help me with the code to make it async???
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12040607
DotNetLover_Baan's solution is much easier.

=)
Idle_Mind
0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 12049228
WHen i declare my sub i have a variable: Private Sub GetSource(ByVal url As String)

called url. I use this when i call it like : GetSource("http://www.google.com")

I did as DotNetLover says but in the statement:

Dim NewProcess As New System.Threading.Thread(AddressOf GetSource)

Underlines the GetSource beause it waits for my url variable. If i put anything in there as i ussualy would it's still underlined. What's the problem???

0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 2000 total points
ID: 12049595
Hi there,
using AddressOf operator in multithreading application, doesn't allow you to pass argument or get any parameter out of it.
http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconParametersReturnValuesForFreeThreadedProcedures.asp

The easier way will be, to declare the "url" variable as global, and later using the value in it.
-Baan
0
 
LVL 1

Author Comment

by:drcyrus3d
ID: 12049969
Thanks a lot DotNetLover_Baan. It worked perfectly.

Thank you all for your quick help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question