Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

VS 2012 Program slows down, general question!

$
0
0
I was bored, so I created a program to calculate dice rolls. Basically, you choose a lucky number and the number of dice you want to throw, and the program throws the dice until every dice has landed on the lucky number. The program counts the throws needed to nail the lucky number. So it's pretty basic, and just a way for me to practice some multi-threading. It's actually the first time I do it.

I decided to put "CheckForIllegalCrossThreadCalls = False" in Form Load, because there should be no other threads accessing the controls at the same time as the calculation is going. I don't know is this is dumb of me, but we'll see.

The problem is basically that if you throw 1 die, the calculation goes pretty fast. 4 dice makes for approximately 500 throws a second on my computer, but the amount of time it takes increases dramatically. 11 dice takes 4 - 5 seconds to complete 500 throws. My general question is basically if this is normal? I know it will take exponentially more throws to get the lucky number on all of the dice, but the whole process just takes a lot longer when the time per throw decreases so dramatically.

Is this because I have chosen a listbox as my preferred "array", or is it just something to expect? I don't have much experience coding, so the probability of mistakes and coding no-no's is probably big. Still, here is the part of my code doing the "throws":

Code:

Private Sub ThreadTask()
        Do
            rolls = rolls + 1
            If rolls > oldrolls + 500 Then
                Label1.Text = rolls
                oldrolls = rolls
            End If

            Results.Items.Clear()
            itemcount = 0

            For k As Integer = 1 To ComboBox1.SelectedItem
                Results.Items.Add(rndm.Next(1, 7))
            Next k

            For Each item In Results.Items
                If item = ComboBox2.SelectedItem Then
                    itemcount = itemcount + 1
                    If itemcount = ComboBox1.SelectedItem Then
                        success = True
                        Label1.Text = rolls
                    End If
                Else
                    Exit For
                End If
            Next

        Loop While success = False And bu3 = False
    End Sub


Viewing all articles
Browse latest Browse all 27349

Trending Articles