Hello guys i'm getting a massive memory leak which over period of 1min its increase alot and always increases.

How to i prevent the memory stacking? I looked all around the internet as im not just posting coz im lazy, i cant find a solution for my code.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If TextBox3.Text = String.Empty Then
            MessageBox.Show("Please enter a subject", "Subject Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        If TextBox3.Text = String.Empty Then Exit Sub
        If TextBox4.Text = String.Empty Then
            MessageBox.Show("Please enter a message", "Message Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        If TextBox4.Text = String.Empty Then Exit Sub
        If TextBox5.Text = String.Empty Then
            MessageBox.Show("Please enter start ID to PM", "Start ID Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        If TextBox5.Text = String.Empty Then Exit Sub
        If TextBox6.Text = String.Empty Then
            MessageBox.Show("Please enter end ID to PM", "End ID Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        Dim abc As Integer
        Dim X As Integer
        X = -1
        If TextBox6.Text = String.Empty Then Exit Sub
        For abc = TextBox5.Text To TextBox6.Text Step 1
            WebBrowser1.ScriptErrorsSuppressed = True
            WebBrowser1.Navigate("http://forum.ea.com/uk/pm/sendTo/" & abc & ".page")
            WebBrowser1.ScriptErrorsSuppressed = True
            While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
                Application.DoEvents()
            End While
            X = X + 1
            Label4.Text = abc
            Label7.Text = X
            Me.Refresh()
            Try
                WebBrowser1.Document.GetElementById("subject").SetAttribute("value", TextBox3.Text)
                WebBrowser1.Document.GetElementById("message").SetAttribute("value", TextBox4.Text)
                WebBrowser1.Document.GetElementById("btnSubmit").InvokeMember("click")
            Catch ex As Exception
                X = X - 1
            End Try
            While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
                Application.DoEvents()
            End While
            Threading.Thread.Sleep(2000)
        Next abc
    End Sub

Can't comment on the WebBrowser portion but I do have a couple of things to point out. You can replace each block of

If TextBox3.Text = String.Empty Then
    MessageBox.Show("Please enter a subject", "Subject Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If TextBox3.Text = String.Empty Then Exit Sub

with

If TextBox3.Text = String.Empty Then
    MessageBox.Show("Please enter a subject", "Subject Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Exit Sub
End If

Also

For abc = TextBox5.Text To TextBox6.Text Step 1

For loops require integer parameters. You have declared abc as integer, however, TextBox5.Text and TextBox6.Text are not integers. You should convert these to integer values (after ensuring that the strings are in fact valid integers).

done changes fellah, thank you, but still its increasing and stacking until forever, :(

any other ideas?

I just thought I'd answer the question you didn't ask. Sorry, but I can't help you with the WebBrowser stuff.

Did you try removing the second

WebBrowser1.ScriptErrorsSuppressed = True

And...

For abc = Cint(TextBox5.Text) To Cint(TextBox6.Text) Step 1

Just taking a wild guess here; I think that this might be the cause of the issue.

While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
                Application.DoEvents()
            End While

Try commenting out the Application.DoEvents() and report back.

The WebBrowser1.ScriptErrorsSuppressed = True can be set "only once" in Form1_Load and it will take care of all Script.Error Messages andOr can be set in the wb(WebBrowser)'s Properties.

Completely uneducated suggestion here, but I noticed that the WebBrowser control has a DocumentCompleted event. Why not use that instead of a wait loop?

Reverend Jim, I completely agree since I also created an automated p.m.s'er:D to send p.m.s:D to those that did not mark their threads Solved or just abandoned their threads, and it did use the _wb_DocumentCompleted event.

i dont know how to do that Jim or i would im new to this coding stuff ya see. can u write the code (Document Complete) that i can do to replace the loop but still acts like one?

Cheers

Can't do. I've never programmed a web interface. The best I could do was make an off the wall suggestion that I hoped might point you in the right direction.

Had a chance to play w/this for a few minutes, though I could Not test.

Public Class Form1
    Private isSendingPMSxD As Boolean = False '// alert wb that it is a p.m. page.
    Private iStartID, iEndID As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.ScriptErrorsSuppressed = True '// disable Error.Messages.
    End Sub

    Private Sub showCoolMessage(ByVal selCoolMessage As String, ByVal selCoolTitle As String) '// just.because.
        MessageBox.Show("Please enter " & selCoolMessage, selCoolTitle & " Required", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Sub

    Private Sub _Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        With TextBox3 : If .Text = "" Then : showCoolMessage("a subject", "Subject") : Exit Sub : End If : End With
        With TextBox4 : If .Text = "" Then : showCoolMessage("a message", "Message") : Exit Sub : End If : End With
        With TextBox5
            If .Text = "" OrElse Not IsNumeric(CInt(.Text)) Then : showCoolMessage("start ID to PM", "Start ID") : Exit Sub
            Else
                iStartID = CInt(.Text)
            End If
        End With
        With TextBox6
            If TextBox6.Text = "" OrElse Not IsNumeric(CInt(.Text)) Then : showCoolMessage("end ID to PM", "End ID") : Exit Sub
            Else
                iEndID = CInt(.Text)
            End If
            : End With
        isSendingPMSxD = True
        wbNavigate(iStartID)
        Button3.Enabled = False
    End Sub

    Private Sub wbNavigate(ByVal selCoolIDtoUse As Integer)
        WebBrowser1.Navigate("http://forum.ea.com/uk/pm/sendTo/" & selCoolIDtoUse & ".page")
    End Sub

    Private Sub _WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If isSendingPMSxD Then
            With WebBrowser1.Document
                .GetElementById("subject").SetAttribute("value", TextBox3.Text)
                .GetElementById("message").SetAttribute("value", TextBox4.Text)
                .GetElementById("btnSubmit").InvokeMember("click")
                Label4.Text = iStartID
                Application.DoEvents()
                If Not iStartID = iEndID Then
                    iStartID += 1 : wbNavigate(iStartID)
                Else
                    isSendingPMSxD = False
                    MsgBox(".done.")
                    Button3.Enabled = True
                End If
            End With
        End If
    End Sub
End Class

Hope it helps.:)

Ah awsome, one problem, after first pm, it tryed to search for subject again before its even reloaded.

Can you provide more details?
.btw, did it take care of the "memory increase leak"?

it was loading the next id to PM but it could not find "Subject" because it did not load completely and crashed, i tryed to "Try" them out but then its flicks through all the ID's nearly instantly.

Cant check memory leak due to this fella. how can i make it wait for page load? as i thought it shud as its in Webbrowsercomplete section.

.Replace the entire _WebBrowser1_DocumentCompleted event w/this.

Private Sub _WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If isSendingPMSxD Then
            Application.DoEvents()
            tmrWb.Start()
        End If
    End Sub

    Private WithEvents tmrWb As New Timer With {.Interval = 500}
    Private Sub _tmrWb_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrWb.Tick
        Static iTimeOut As Integer = 0
        If Not iTimeOut = 3 Then '// roughly 1.5 sec.
            iTimeOut += 1
            Exit Sub
        Else
            iTimeOut = 0 '// reset timeOut.
            tmrWb.Stop() '// stop timer.
            With WebBrowser1.Document
                .GetElementById("subject").SetAttribute("value", TextBox3.Text)
                .GetElementById("message").SetAttribute("value", TextBox4.Text)
                .GetElementById("btnSubmit").InvokeMember("click")
            End With
            Label4.Text = iStartID
            If Not iStartID = iEndID Then
                iStartID += 1 : wbNavigate(iStartID) : Exit Sub
            Else
                isSendingPMSxD = False
                MsgBox(".done.")
                Button3.Enabled = True
            End If
        End If
    End Sub

I added a Timer to give it a TimeOut. Set the Timer's.Interval as needed, If needed.

quick.suggestion before .Replacing the event:
.Add "Application.DoEvents()" as the very first line of code in the wb.doc.completed event. Might or might Not Return results.
---
>>Cant check memory leak due to this fella.
If "this fella" is Waldo, I'll never get an answer, cause I can never find his butt anywhere.:D

yo fella, tryed the Application.DoEvents() just after decument complete but still trys to find subject during page load.

The timer is usefull and works but will at alot of time to the duration over x hours. any chance to fix the page load thing fella?

and thank you for all your help so far

Since I cannot test it(no EA acct.), Not much at all I can do about it. Wish you luck and glad that I could be of help so far.:)

q.q.(quick.question)
Have you tested to see If it still has the memory leak?

.idea/suggestion.
Have you tried this w/multiple WebBrowsers?

no memory leak :) no fella i aint i tryed to adjust it to use multi browsers but i had no luck lol do u mind adding a few maybe 4?

Should I build and design the entire project also?:D

Here are some notes.
Add your 4 wb's and add 4 Timers.
Other than that, good luck.:)

awsome yeah i done that, but i mite change bk to one, and allow them to open multi programs for more speed.

btw any way to make this wait until page load and not timer?

See if this helps.

Private sInnerHtml As String
    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        sInnerHtml = WebBrowser1.Document.Body.InnerHtml
        With sInnerHtml.ToLower
            If .Contains("=""subject""") AndAlso .Contains("=""message""") AndAlso .Contains("=""btnSubmit""") Then
                '// run code here to post.
            End If
        End With
    End Sub

.might need a space here and there, though it should take care of the issue of Not using a Timer.

there is still a memory leak, :( i dont know why

No memory.leak prior to the recently posted code?or the memory.leak was always there?
In any case, I provided what I know as a hobbyist vb.noob, good luck from here on out.:)

ah :( erm nar it was still increasing, i added some more code tho.

Private WithEvents tmrWb As New Timer With {.Interval = 500}
    Private Sub _tmrWb_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrWb.Tick
        Static iTimeOut As Integer = 0
        Static X As Integer = 0

        If Not iTimeOut >= 3 Then '// roughly 1.5 sec.
            iTimeOut += 1
            Exit Sub
        Else
            iTimeOut = 0 '// reset timeOut.
            tmrWb.Stop() '// stop timer.
            Try
                With WebBrowser1.Document
                    .GetElementById("subject").SetAttribute("value", TextBox3.Text)
                    .GetElementById("message").SetAttribute("value", TextBox4.Text)
                    .GetElementById("btnSubmit").InvokeMember("click")
                End With
            Catch Exception As Exception
            End Try
            Label8.Text = X
            X = X + 1
            Label4.Text = iStartID
            tmrWb2.Start()
        End If
    End Sub


    Private WithEvents tmrWb2 As New Timer With {.Interval = 500}
    Private Sub _tmrWb2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrWb2.Tick
        Static iTimeOut1 As Integer = 0
        If Not iTimeOut1 >= 4 Then '// roughly 1.5 sec.
            iTimeOut1 += 1
            Exit Sub
        Else
            iTimeOut1 = 0 '// reset timeOut.
            tmrWb2.Stop() '// stop timer.
            If Not iStartID = iEndID Then
                iStartID += 1 : wbNavigate(iStartID) : Exit Sub
            Else
                isSendingPMSxD = False
                MessageBox.Show("Process Complete!", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Button3.Enabled = True
            End If

        End If
    End Sub

Any last tips codeorder my friend :) ?

>>Any last tips...
:(

i can find no way to stop the increase. its impossible!

>>i can find no way to stop the increase. its impossible!
I can. Just don't use your .app.:D

Bah, so any one with a problem with memory leak your just saying give up coding =/ then no1 will need to visit this forum :O

Do you have loop in your code?

>>Bah, so any one with a problem with memory leak your just saying give up coding =/ ...
Why Not?if they can't fix the issue.
.just makes the programs I download/use work better.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.