-
Thread - Two Proesses
I have some problems in Thread [.Net].
There are two forms in my project such as frmMain and frmProgressBar.
I write some codes to load many data from Database in frmMain_Load() Event.
I want to display progressbar while the data are loading from the database.
How should I do?
I have tried with these codes
In frmMain_Load() Event
Code:
Dim dataloader As New System.Threading.ThreadStart(AddressOf LoadData)
Dim newThread As New System.Threading.Thread(dataloader)
newThread.Start()
ds = ObjMailCenter.GetMails
tdbMailsList.DataSource = ds.Tables(0)
tdbMailsList.Refresh()
Code:
Private Sub LoadData()
Dim ObjProgressBar As New frmProgressBar
ObjProgressBar.Show()
System.Threading.Thread.Sleep(1000)
End Sub
In frmProgressbar, there is one timer to change the value of progressbar.
Any help would be appreciated. :-)
-
A progress bar works well with a task like copying files, because you know the total amount of work to do (e.g., the total number of files) and how much of the work you've completed so far (e.g., how many files you've finished copying). It's also easy to break up the task into units; you can, for example, update the progress bar after each file is finished copying.
With a database transaction, however, your code has no way of knowing how long it's going to take or how much of the task has completed, so a progress bar doesn't make much sense. Instead, you might try using a technique like the one described in this article: http://msdn.microsoft.com/msdnmag/is...dvancedBasics/
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Thanks.
That's why, what i was planning to do is
first, I want to display "main form". [It's first thread.] I don't want to bind data from database at that time.
And then, I want to show "ProgressBar". [It's second thread.]
Then, I want to bind the data from "MainForm" while the "ProgressbarForm" will be displaying the progress between min value and max value of the progressbar again and again.
finally, I want to hide "ProgressBar Form" as soon as Data Binding Complete.
So, I don't need to know how much time it will take to bind the data from the database.
If data binding process is completed. you can to close "Progressbar Form".
That is. :-)
-
With what part of that process do you need help?
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
Code:
Module modGlobal
Public Splash As New frmSplash 'Your Splash Form
Dim newThreadProgressBar As New System.Threading.Thread(AddressOf NewThreadProcedureForProgressbar)
Dim newThreadRoot As New System.Threading.Thread(AddressOf NewThreadProcedure)
Sub NewThreadProcedure()
Application.Run(New Root(True))
End Sub
Sub NewThreadProcedureForProgressbar()
Application.Run(New frmProgressBar(True))
End Sub
Public Sub Main()
Splash.Show()
Application.DoEvents()
newThreadRoot.Sleep(1000) 'Allows Extra Display time of Splash Screen
newThreadRoot.Priority = Threading.ThreadPriority.Highest
newThreadRoot.Start()
Application.DoEvents()
newThreadProgressBar.Sleep(1000) 'Allows Extra Display time of Splash Screen
newThreadProgressBar.Priority = Threading.ThreadPriority.BelowNormal
newThreadProgressBar.Start()
Application.DoEvents()
End Sub
End Module
I wrote like that.
the "ProgressbarForm" will be displaying the progress between min value and max value of the progressbar again and again during the data are still binding in "Main Form".
When data has been binded, I want to close "frmProcessBar" form.
How can I close this Form??
-
You must declare ProgressBarForm so that it is visible to the procedure doing the data binding. Instead of Application.Run(New frmProgressBar(True)), try declaring the ProgressBarForm alongside the Splash form:
Public Splash As New frmSplash
Public ProgressBarForm As New frmProgressBar
NewThreadProcedureForProgressbar then becomes:
Application.Run(ProgressBarForm)
Then you may simply close modGlobal.ProgressBarForm when your data binding is complete.
Phil Weber
http://www.philweber.com
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
-
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks