View Single Post
  #6 (permalink)  
Old 12-03-2008, 7:11 AM
cjard's Avatar
cjard cjard is offline
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Quote:
Originally Posted by Solitaire View Post
The following works for me:
But, it doesnt work for the OP

He wants to count to.. say.. a million.. And he wants to see the numbers rolling up in the text box from 1 to a million (or the text extending each time). He does not want to click the Go button, and have the UI hang for 30 seconds while VB concatenates a million strings together and stores them in a text box and only reveals the result at the end, hence why MattP provided the BackgroundWorker example


hscorpio: note that MattP's example replaces the text each time. If you want to append the text each time, use textbox.AppendText("text") in place of textbox.Text = "text"

Note also that you DONT have to use e.ProgressPercentage (you can set it to 0 always, or use it to pass status codes) nor does it have to be a progress percentage at all; it can jump up and down and be totally unrelated to your operation's progress.
You can pass any information you like in the UserState parameter; MattP passes a number, i, but it can be a string, number, error, anything. At the other side, in the ProgressChanged event handler, convert the userstate back to what you want with DirectCast(e.UserState, <type>).
e.g. Suppose you had a custom class ReportState, you would

Code:
Dim myReportState as New ReportState
...
BackgroundWorker1.ReportProgress(i / 100, myReportState)

...
'and in the progress changed event handler:

...
Dim tmpRepState as ReportState = DirectCast(e.UserState, ReportState)
'now do whatever you want with the reportstate object
As an example, when using a background worker, i'll use the progress percentage as the level of logging from 0 to 5 (low to high) and the userstate as the message i want to log. You can also use the TypeOf() command to see what kind of object the UserState is, and perform different actions depending on what it is
__________________
DW1 DW2 DW3 DW4 DNU PQ

Last edited by cjard; 12-03-2008 at 7:16 AM.
Reply With Quote