Labels not showing till processing complete

HWT

New member
Joined
Nov 9, 2004
Messages
4
Programming Experience
Beginner
I am currently having problems with a windows form not displaying correctly.



I have created a form that shows the progress of the current operation (includes a progress bar). This form is called from a class the performs a lot of work. The problem is the labels on this form do not appear until the process has finished.



If I just show the form and have no processing it displays correctly.

If I show the form and then do the processing the form does not show the labels.



Does anyone know how i can get around this problem?



Thanks.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
are you updateing the label's dureing the processing routine(s)? post a basic layout of what 'processing' entails
 

HWT

New member
Joined
Nov 9, 2004
Messages
4
Programming Experience
Beginner
overview

Hi,



This is a very basic overview of what I am trying to do.



Dim count As Integer

Dim myform as new form

Dim Maxcount as interger



Maxcount = 100000



myform.show()

myform.ProgressBar1.Maximum = Maxcount

For count = 0 To Maxcount

myform.ProgressBar1.PerformStep()

Next

messagebox.show("Done")

myform.close()



I am only updating the progress bar on this form while it is processing. The progress bar displays correctly, but the labels do not display till it reaches the messagebox (the processing is complete)



Thanks for your help.
 

HWT

New member
Joined
Nov 9, 2004
Messages
4
Programming Experience
Beginner
Used Threads to fix problem.

Hi I worked it out... I used a thread to show the form and it appears to work.

Dim myform As New Form
Dim thr as Thread

Private Sub Run()

Dim count As Integer

Try
thr = New Thread(New ThreadStart(AddressOf formshow))

thr.Start()
For count = 0 To 100000
'processing
myform.ProgressBar1.PerformStep()
Next
myform.Close()

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

Private Sub formshow()
Dim dr As DialogResult
myform.ProgressBar1.Maximum = 100000
dr = myform.ShowDialog
MessageBox.Show("Finished")

End Sub

If there is a better way to do this without threads... would love to see it...
Thanks
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
You could call the Application.DoEvents procedure which will allow the form's paint method to execute and the labels should appear. I would stick with the thread though.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
i agree with paszt, you have (in my belief) more control in your application if you stick with threading
 
Top Bottom