|
-
Oct 17th, 2010, 04:15 AM
#1
Thread Starter
Member
Progress Bar - Threading - Minimizing Window
Hey guys,
Now I know what I am about to describe is generally considered bad practice, so just bare with me as I describe it.
Part of my application deals with creating a number of pivot tables. I pull data from a local database, and store it in a datatable. From here, the data is processed and eventually a pivot table is returned. On small data sets it works well, but on some larger one there is a few seconds of "nothing" until the table is shown.
After a few iterations of trying things to display some form of progress I have ended up with a form with nothing but a progress bar running on it. I spawn a new thread, and run it. It works exactly like I hoped. However, when I call the thread.abort() method to terminate the thread, occasionally, the main form will minimize. I tired having me.show() aftre the .abort() to bring the form into view again, but it appears not to have helped.
Now I understand that it is better practice to have worker background threads, and the main thread for UI, but is there a simple way of ensuring that the main form does not close?
Code:
Private Sub LoadProgressForm()
Dim progressForm As New ProgressBar
progressForm.ShowDialog()
End Sub
Private Sub DoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewButton.Click
Dim t As New Thread(AddressOf LoadProgressForm)
t.Start()
'code that does stuff to do with pivoting
t.abort()
me.show()
End Sub
Thanks
Last edited by timmeh_041; Oct 17th, 2010 at 04:19 AM.
Reason: added code
-
Oct 17th, 2010, 04:35 AM
#2
Re: Progress Bar - Threading - Minimizing Window
You shouldn't be showing the progress dialogue on the secondary thread. You should be showing the dialogue on the UI thread and then doing the processing on the secondary thread.
-
Oct 17th, 2010, 04:56 AM
#3
Thread Starter
Member
Re: Progress Bar - Threading - Minimizing Window
Yeah I know. I was just trying to take the lazy mans way and avoid having to rewrite alot of things. The pivottable function takes in a number of parameters, and it is my understanding I can not simply pass these through to the thread.
In order to change it up in that manner, I have to put the function into its own class, correct? So the parameters are variables within that class, and have the function as one of the classes functions? How would I go about returning a value (ie. a datatable) from the secondary thread once it has been completed?
Do you recommend any good links/tuts to read? I read a couple simple ones, but I am not really sure what I am looking for to do what I need done.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|