Results 1 to 11 of 11

Thread: [RESOLVED] Program freezes when getting to meassagebox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Location
    Netherlands
    Posts
    136

    Resolved [RESOLVED] Program freezes when getting to meassagebox

    Good day,

    I have some code in a button click event and after the code i want the messagebox to show, but the program freezes see below code
    Code:
     Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    
            Dim sum As Decimal
            Try
                For Each r As DataGridViewRow In Me.RestHours2DataGridView.Rows
                    If r.Cells IsNot DBNull.Value Then
                        sum = (r.Cells(1).Value + r.Cells(2).Value + r.Cells(3).Value + r.Cells(4).Value + r.Cells(5).Value _
                            + r.Cells(6).Value + r.Cells(7).Value + r.Cells(8).Value + r.Cells(9).Value + r.Cells(10).Value _
                            + r.Cells(11).Value + r.Cells(12).Value + r.Cells(13).Value + r.Cells(14).Value + r.Cells(15).Value _
                            + r.Cells(16).Value + r.Cells(17).Value + r.Cells(18).Value + r.Cells(19).Value + r.Cells(20).Value _
                            + r.Cells(21).Value + r.Cells(22).Value + r.Cells(23).Value + r.Cells(24).Value + r.Cells(25).Value _
                            + r.Cells(26).Value + r.Cells(27).Value + r.Cells(28).Value + r.Cells(29).Value + r.Cells(30).Value _
                            + r.Cells(31).Value + r.Cells(32).Value + r.Cells(33).Value + r.Cells(34).Value + r.Cells(35).Value _
                            + r.Cells(36).Value + r.Cells(37).Value + r.Cells(38).Value + r.Cells(39).Value + r.Cells(40).Value _
                            + r.Cells(41).Value + r.Cells(42).Value + r.Cells(43).Value + r.Cells(44).Value + r.Cells(45).Value _
                            + r.Cells(46).Value + r.Cells(47).Value + r.Cells(48).Value) / -2
                        r.Cells(51).Value = sum
                    End If
    
                Next
    
                For Each row As DataGridViewRow In Me.RestHours2DataGridView.Rows
    
                    Me.RestHours2TableAdapter.SaveQuery(row.Cells(55).Value, row.Cells(0).Value, row.Cells(1).Value, row.Cells(2).Value,
         row.Cells(3).Value, row.Cells(4).Value, row.Cells(5).Value, row.Cells(6).Value, row.Cells(7).Value, row.Cells(8).Value,
                                                         row.Cells(9).Value, row.Cells(10).Value, row.Cells(11).Value, row.Cells(12).Value,
                                                         row.Cells(13).Value, row.Cells(14).Value, row.Cells(15).Value, row.Cells(16).Value,
                                                         row.Cells(17).Value, row.Cells(18).Value, row.Cells(19).Value, row.Cells(20).Value,
                                                         row.Cells(21).Value, row.Cells(22).Value, row.Cells(23).Value, row.Cells(24).Value,
                                                         row.Cells(25).Value, row.Cells(26).Value, row.Cells(27).Value, row.Cells(28).Value,
                                                         row.Cells(29).Value, row.Cells(30).Value, row.Cells(31).Value, row.Cells(32).Value,
                                                         row.Cells(33).Value, row.Cells(34).Value, row.Cells(35).Value, row.Cells(36).Value,
                                                         row.Cells(37).Value, row.Cells(38).Value, row.Cells(39).Value, row.Cells(40).Value,
                                                         row.Cells(41).Value, row.Cells(42).Value, row.Cells(43).Value, row.Cells(44).Value,
                                                         row.Cells(45).Value, row.Cells(46).Value, row.Cells(47).Value, row.Cells(48).Value,
                                                         row.Cells(52).Value, row.Cells(49).Value, row.Cells(50).Value, row.Cells(51).Value,
                                                         ComboBox1.Text, ComboBox2.Text, row.Cells(56).Value)
                Next
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
            MessageBox.Show("Records saved.")
        End Sub
    I have some other code in a click event that does not freeze with the click event and with a messagebox.show
    Code:
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            ComboBox1.Text = TextBox2.Text
            ComboBox2.Text=TextBox3.text
            For Each row As DataGridViewRow In RestHours2DataGridView.Rows
                Me.RestHours2TableAdapter.InsertQuery(row.Cells(55).Value, row.Cells(0).Value, row.Cells(1).Value, row.Cells(2).Value,
     row.Cells(3).Value, row.Cells(4).Value, row.Cells(5).Value, row.Cells(6).Value, row.Cells(7).Value, row.Cells(8).Value,
                                                     row.Cells(9).Value, row.Cells(10).Value, row.Cells(11).Value, row.Cells(12).Value,
                                                     row.Cells(13).Value, row.Cells(14).Value, row.Cells(15).Value, row.Cells(16).Value,
                                                     row.Cells(17).Value, row.Cells(18).Value, row.Cells(19).Value, row.Cells(20).Value,
                                                     row.Cells(21).Value, row.Cells(22).Value, row.Cells(23).Value, row.Cells(24).Value,
                                                     row.Cells(25).Value, row.Cells(26).Value, row.Cells(27).Value, row.Cells(28).Value,
                                                     row.Cells(29).Value, row.Cells(30).Value, row.Cells(31).Value, row.Cells(32).Value,
                                                     row.Cells(33).Value, row.Cells(34).Value, row.Cells(35).Value, row.Cells(36).Value,
                                                     row.Cells(37).Value, row.Cells(38).Value, row.Cells(39).Value, row.Cells(40).Value,
                                                     row.Cells(41).Value, row.Cells(42).Value, row.Cells(43).Value, row.Cells(44).Value,
                                                     row.Cells(45).Value, row.Cells(46).Value, row.Cells(47).Value, row.Cells(48).Value,
                                                     row.Cells(52).Value, row.Cells(49).Value, row.Cells(50).Value, row.Cells(51).Value,
                                                     row.Cells(53).Value, row.Cells(54).Value)
            Next
    
            MessageBox.Show("Records created")
        End Sub
    I have tried the messagebox.show also in the update event from the tableadapter and also there it freezes the program.

    Also the tables gets updated so nothing wrong there it is just as it reaches the messagebox.show that it gets stuck

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Program freezes when getting to meassagebox

    Have you debugged the code? If not, do that. If you have where exactly does it freeze? Are you saying, without actually saying, that the MessageBox.Show call is executed but never returns?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Location
    Netherlands
    Posts
    136

    Re: Program freezes when getting to meassagebox

    Yes i did the debugging, also when i remove the messagebox(es).show it does everything what has been coded and the program does not freeze

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Location
    Netherlands
    Posts
    136

    Re: Program freezes when getting to meassagebox

    When i replace the messagebox.show to ME.close it closes the program so why does it not show the messagebox

  5. #5
    Fanatic Member Arve K.'s Avatar
    Join Date
    Sep 2008
    Location
    Kyrksæterøra, Norway
    Posts
    518

    Re: Program freezes when getting to meassagebox

    Does putting the messagebox in a finally block make any difference?
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem
    Disclaimer: I am not a professional programmer

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Location
    Netherlands
    Posts
    136

    Re: Program freezes when getting to meassagebox

    No it does not also, i see now that when i create a mistake the catch messagebox also does not show

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Location
    Netherlands
    Posts
    136

    Re: Program freezes when getting to meassagebox

    Allright i found the problem the mistake is/was that the messagebox was behind the form when i pushed ALT it was showing.
    I have resolved it by this peace of code in the messagebox section:
    Code:
     MessageBox.Show("Records saved.", "Info",
                    MessageBoxButtons.OK, MessageBoxIcon.Information,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly)
    But still it is strange this happens for some messageboxes and others working fine

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: Program freezes when getting to meassagebox

    Quote Originally Posted by zubenubie View Post
    But still it is strange this happens for some messageboxes and others working fine
    I've seen that happen with code executed on secondary threads but not on the UI thread. I wonder whether it has something to do with the fact that you're doing a lot of work there on the UI thread first. How long does it actually take for the message box to show? I have to wonder why you are looping over the rows of the grid and saving one record at a time instead of just making one call to Update and saving the changes directly from a DataTable.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Location
    Netherlands
    Posts
    136

    Re: [RESOLVED] Program freezes when getting to meassagebox

    The database table holds various months and years from various people and when i do the UpdateAll it will update all the records/rows with that month and year which are loaded in the datagridview.
    If it can be made more efficient i really would like to know. If i have around 1500 rows in the databasetable it takes about a second or less for the messagebox to show.
    The table will hold about max 12000 records as the records have to bekept for 5 years.

  10. #10
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: [RESOLVED] Program freezes when getting to meassagebox

    Have you thought about not updating 12000 records at once? Not like a user can see all. I do not do database work I would imagine there is a way to load x amount when needed.

    I will pass this on to a friend who does nothing but database work and see if he has some ideas.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2017
    Location
    Netherlands
    Posts
    136

    Re: [RESOLVED] Program freezes when getting to meassagebox

    As i see it i am not updating all records only the one in the datagridview

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width