The application crashes when a form appears

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
KraZy
Top Poster
Top Poster
Posts: 93
Joined: Sat May 26, 2012 8:40 am

I made a code which is able to save in two lists results in real time from a web page, so far everything has worked very well, then I decided to add an additional feature and that is to show the results that have changed (ie when a team scored a goal), in a form of notifications. I then made an additional form called "notifiche" and I implemented the procedure as follows:
Code: Select all
Dim keepLogging As Boolean = True

            If popup = True Then 'this variable is valorized when the form's minimized

                For Each abc As Country_Data In lista
                    For Each xyz As Country_Data In vecchia_lista
                        If abc.casa = xyz.casa And abc.ospite = xyz.ospite Then
                            If abc.result <> xyz.result Then
                               'function that show the notification
                                show_popup(abc.casa, abc.ospite, abc.minuto, abc.result)
                                keepLogging = False
                                Exit For
                            End If
                        End If
                    Next
                    If (Not keepLogging) Then Exit For
                Next
            End If
all the code works very well, the results that have changed are shown, the problem lies in the form of notification. In particular when the notification should appear the application crashes. I can't explain why because if I open the form "notifiche" for example by pressing a button with "notifiche.show()", this shows no problem opening.
Code: Select all
Function show_popup(casa, ospite, risultato, minuto)
        notifiche.Show()
        notifiche.MetroLabel1.Text = casa
        notifiche.MetroLabel2.Text = risultato
        notifiche.MetroLabel3.Text = ospite
        notifiche.MetroLabel4.Text = minuto
End Function
This is the class of notifiche form:
Code: Select all
Public Class notifiche
Dim i As Integer = 0
Private Sub notifiche_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.Location = New Point( _
        Screen.PrimaryScreen.Bounds.Width - 400, _
        Screen.PrimaryScreen.Bounds.Height)
   End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If Me.Opacity = 0 Then Me.Close()

    If i = 500 Then
        Me.Opacity -= 0.02
    End If

    If Not Me.Location.Y = Screen.PrimaryScreen.WorkingArea.Height - 200 Then
        Me.Location = New Point(Me.Location.X, Me.Location.Y - 2)
    End If

    If Not i = 500 Then i += 1
End Sub
End Class
I also tried with adding exceptions, but there isn't exception generated. I tried with a simple form without anything in the class and the problem is the same. I think that is a problem of the loop at this point.
I'm in the empire business.
User avatar
Ffenixw0rks
VIP - Donator
VIP - Donator
Posts: 152
Joined: Sun Jun 19, 2011 2:51 pm

Hmm.. Your code is working fine on my setup..
Take look at your passed params in show_popup and what params are you passing. Maybe there is a typo.
Next try to place breakpoint at
Code: Select all
If abc.result <> xyz.result Then
and go step by step to find where your app crashes.
Image
User avatar
KraZy
Top Poster
Top Poster
Posts: 93
Joined: Sat May 26, 2012 8:40 am

I solve put a BackgroundWorker instead of the thread.
I used the thread and seems that the need create a delegate of main thread for run a new form to another thread.
I'm in the empire business.
3 posts Page 1 of 1
Return to “Coding Help & Support”