FrankZA
April 9th, 2008, 07:55 AM
Hi
I am busy writing a program that is supposed to evaluate some algorithms (by time or result). When the program loads, a form appears. Once some selections in comboboxes have been made, the "Start" button begins the process.
I have used threads so that I can change the priority. Result evaluation can be run on a "belownormal" priority, while the time evaluation would be better when running on "highest" priority so that anything else that Windows is running has a lesser effect (or am I wrong here).
My code has the following structure:
Public Class Form1
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Dim C1 as New Class1
Call C1.NotCompare()
C1 = Nothing
End Sub
End Class
Public Class Class1
Public Sub NotCompare()
Dim t As Threading.Thread
t = New Threading.Thread(AddressOf Me.Compare)
t.Priority = ThreadPriority.AboveNormal
t.Start()
Thread.Sleep(0)
End Sub
Public Sub Compare()
Dim i as Integer
For i = 0 to AlgorithmList.GetUpperBound(0)
Form1.AlgorithmLabel.Text = AlgorithmList(i).Name 'This is where the problem lies I think
Next
i = Nothing
End Sub
End Class
I am attempting to to write the name of the algorithm to the label AlgorithmLabel on the original form Form1. I also want to write the name of the dataset in use to the form so that the user knows how far along the calculations the thread is (I assume this would be done in the same way).
How would I approach this problem of changing the label's text from a thread? Or is there a better approach?
Also, is it useful to use the Sleep(0) option at all?
Thanks...
I am busy writing a program that is supposed to evaluate some algorithms (by time or result). When the program loads, a form appears. Once some selections in comboboxes have been made, the "Start" button begins the process.
I have used threads so that I can change the priority. Result evaluation can be run on a "belownormal" priority, while the time evaluation would be better when running on "highest" priority so that anything else that Windows is running has a lesser effect (or am I wrong here).
My code has the following structure:
Public Class Form1
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Dim C1 as New Class1
Call C1.NotCompare()
C1 = Nothing
End Sub
End Class
Public Class Class1
Public Sub NotCompare()
Dim t As Threading.Thread
t = New Threading.Thread(AddressOf Me.Compare)
t.Priority = ThreadPriority.AboveNormal
t.Start()
Thread.Sleep(0)
End Sub
Public Sub Compare()
Dim i as Integer
For i = 0 to AlgorithmList.GetUpperBound(0)
Form1.AlgorithmLabel.Text = AlgorithmList(i).Name 'This is where the problem lies I think
Next
i = Nothing
End Sub
End Class
I am attempting to to write the name of the algorithm to the label AlgorithmLabel on the original form Form1. I also want to write the name of the dataset in use to the form so that the user knows how far along the calculations the thread is (I assume this would be done in the same way).
How would I approach this problem of changing the label's text from a thread? Or is there a better approach?
Also, is it useful to use the Sleep(0) option at all?
Thanks...