Crash without an error (debugmodus) // Threads

sollniss

Member
Joined
Aug 5, 2008
Messages
12
Programming Experience
3-5
VB.NET:
Imports System.Threading
Imports WindowsApplication1.modFunktionen

Public Class frmMain

    Private strTempLinks As String
    Private strTempMails As String

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
        Dim strSource As String = GetSourcecode(txtUrl.Text)

        Dim strLinks As ArrayList = GetLinks(strSource)
        For i As Integer = 0 To strLinks.Count - 1
            txtLinks.Text &= strLinks(i) & Environment.NewLine
        Next

        Dim strMails As ArrayList = GetMails(strSource)
        For i As Integer = 0 To strMails.Count - 1
            txtMails.Text &= strMails(i) & Environment.NewLine
        Next

        Dim thrRekusiv(strLinks.Count - 1) As Thread
        For i As Integer = 0 To strLinks.Count - 1
            thrRekusiv(i) = New Thread(AddressOf Spider)
            thrRekusiv(i).Start(strLinks(i).ToString)
        Next

    End Sub

    Private Sub Spider(ByVal sLink As String)
        Dim strSource As String = GetSourcecode(sLink)

        Dim strLinks As ArrayList = GetLinks(strSource)
        For i As Integer = 0 To strLinks.Count - 1
            strTempLinks &= strLinks(i) & Environment.NewLine
        Next

        Dim strMails As ArrayList = GetMails(strSource)
        For i As Integer = 0 To strMails.Count - 1
            strTempMails &= strMails(i) & Environment.NewLine
        Next

        'Dim thrRekusiv(strLinks.Count - 1) As Thread
        'For i As Integer = 0 To strLinks.Count - 1
        '    thrRekusiv(i) = New Thread(AddressOf Spider))
        '    thrRekusiv(i).Start(strLinks(i).ToString)
        'Next
    End Sub

    Private Sub timAktuell_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timAktuell.Tick
        If strTempLinks <> "" Then
            txtLinks.Text &= strTempLinks
            strTempLinks = ""

            'txtLinks.SelectionStart = txtLinks.Text.Length
        End If

        If strTempMails <> "" Then
            txtMails.Text &= strTempMails
            strTempMails = ""

            'txtMails.SelectionStart = txtMails.Text.Length
        End If
    End Sub
End Class

Someone an idea?
Maybe a logical flaw?
 
In Short: Nobody will help you fast with that post.

You missed following points:
* Telling what exactly the error is
* Telling what the code is about
* Telling what you want to achieve
* Begging *eg*

But...as I can see the Spider Sub isn't doing anything. And there might be an issue 'cause you're accessing a control from another Thread (timAktuell_Tick and txtLinks.Text). have a look at the Invoke functions for multi-threading.

Bobby
 
Thx for your reply.

* Telling what exactly the error is
There is no error, just a crash.

*Telling what the code is about
The code gets a sourcecode from a webpage and filters out all the links and emails.
For each link found, there should start a new thread filtering each link out of the link's source. etc.

* Telling what you want to achieve
I want to get the crash fixed. And the code working. ^^

* Begging
So pleeeease help me. :D

But...as I can see the Spider Sub isn't doing anything.
VB.NET:
            thrRekusiv(i) = New Thread(AddressOf Spider)
            thrRekusiv(i).Start(strLinks(i).ToString)
The Spider-Sub don't starts any deeper threads yet, theres only one instance of filtering links and mails.

And there might be an issue 'cause you're accessing a control from another Thread
Nope. The Rekusiv-Threads are writing the links into global variables.
There is a timer in the GUI-Thread checking these vars and putting them into the textboxes.

Hope you understand it. :/
 
Ahh...you could try to add Try...Catch Statements to the Thread-Code, which are writing the Exceptions Messages to the Debug.Print. Might give a clue what is going wrong.

Bobby
 
I've done that, but there was no error message. :D
I think is was a performance error, because after i added some Application.DoEvents() everything's working fine.

But I've got another 2 questions:
Do you have an idea how I can find out when the code is finished?
How I can abort the createt threads e.g. by a button in the GUI-Thread?
 
You could save the Thread-Objects. They have a Property called ThreadState which indicates the actuell state of the thread. Also you can abort the thread from there the Sub Suspend to stop the Thread.

Bobby
 
Back
Top