VB newbie problem

M

Matt Douhan

Hello

I have a small VB APP, that runs on on the end users PC, ever n seconds it
connects to a webserver and runs a webpage and stores a local file.

My problem is that it takes way to much resources, when the program is
active the PC becomes almost unusable so I am sure I have missed something,
I want the program to live in the background and do its thing without
affecting the peformance of the users PC.

the code snippet is al follows

Private Sub tmr_main_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles tmr_main.Tick

Dim byteData() As Byte

Dim intFile As Integer

Dim strURL As Char

Dim cmd As Char

Dim fire As Integer

If chkboxdebugflag = 2 Then

Else

On Error Resume Next

End If

Dim wr As HttpWebRequest =
CType(WebRequest.Create("http://www.fruitsalad.org/people/mdouhan/test/foo.t
xt"), HttpWebRequest)

Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)

Dim str As Stream = ws.GetResponseStream()

Dim inBuf(100000) As Byte

Dim bytesToRead As Integer = CInt(inBuf.Length)

Dim bytesRead As Integer = 0

While bytesToRead > 0

Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)

If n = 0 Then

Exit While

End If

bytesRead += n

bytesToRead -= n

End While

Dim fstr As New FileStream("foo.txt", FileMode.OpenOrCreate,
FileAccess.Write)

fstr.Write(inBuf, 0, bytesRead)

str.Close()

fstr.Close()

Dim wrrm As HttpWebRequest =
CType(WebRequest.Create("http://www.fruitsalad.org/people/mdouhan/test/bar.p
hp"), HttpWebRequest)

Dim wsrm As HttpWebResponse = CType(wrrm.GetResponse(), HttpWebResponse)

Dim strrm As Stream = wsrm.GetResponseStream()

' here we need the code to first copy the file to \\%machinename%\zebra but
until I learn how I have to use an ugly .cmd file, maybe someone can help me

' would be nice to have a copy file.txt ltp1 and then del /y file.txt in
this code instead of the cmd file, but I guess thats what I get for being a
newbie

Shell("printit.cmd")



Any help would be great



rgds



Matt
 
B

Bismark Prods

Hello,

You could doing it in a separate thread with an asynchronous method. The
fact that the method is asynchronous, means your PC can work during the
process.

Good night lol

Bismark
 
C

Cor

Hi Matt,

In my idea will Multithreading not help you much in my idea for this
problem.
You only replace the problem.

Look what this could do for you?
While bytesToRead > 0
threading.thread.sleep(1000) ' this is one second
Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While

And it is the best way to place only one problem per message to a newsgroup,
someone knows one answer but not the other and than you do often not get an
answer at all.

Moreover answering more questions in one time becomes confusing.

I hope this one helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top