-
Apr 11th, 2011, 11:35 AM
#1
[RESOLVED] Threading a progressbar
I've done some threading before, but usually standalone methods that were part of a batch file.
I've looked into BackgroundWorker, Thread and using a delegate to pass parameters into a thread, but I think my issue may lie in the fact I am having a hard time seeing how I would want this to flow.
The logic I'm looking for is prettymuch as below
Code:
pb.Initialize(0, this.csv.Count - 1);
pb.Show();
//start at 1 to avoid the headers
for (int x = 1; x < this.csv.Count; x++)
{
Match match = new Match(this.maxi.GetHost(), this.maxi.GetLogin(), this.cmbDupFields.Text);
List<string> line = this.csv[x];
List<Client> duplicatesFound = match.CheckMatch(matchFields, line);
if (duplicatesFound.Count == 0)
{
string recordCreated = this.maxi.CreateRecord(line, fields);
if (recordCreated != string.Empty)
{
this.recordsCreated.Add(recordCreated);
}//end if
}
else
{
duplicates.AddRange(duplicatesFound);
}//end if
pb.Increment();
}//end for
pb.Close();
There are a few classes in there, but they shouldn't really be worried about. Progress is a windows form that holds my progressbar.
I'm trying to figure out how I want to thread this to allow interaction with the UI while the process is running. My first thought was to just thread
Code:
string recordCreated = this.maxi.CreateRecord(line, fields);
But even when I remove all of the content in the for loop, the UI freezes regardless, so I figured I would need to put all of the code above into a separate method and run that in its own thread. Problem with that is that the method itself calls several objects on the form to get the data it requires.
I've thought of a few different ways, but when I've tried to implement them it hasn't worked out in my favour.
Could someone possibly point me in the right direction with this? I would prefer not having to call any code from the progress window, but if it is required, I can work around it.
-
Apr 11th, 2011, 02:49 PM
#2
Re: Threading a progressbar
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
-
Apr 12th, 2011, 09:10 AM
#3
Re: Threading a progressbar
Thanks for the response, I guess I worded that incorrectly.
I was more hoping for some input on how I could achieve it using my own scenario, but I figured it out. I already knew how to use the backgroundworker and threading, and using anonymous delegates to access the UI thread, but I wasn't sure how to incorporate it into my thread.
Long story short, I created a method where I passed in all of the UI data I required. Then I called the showdialog method of my form to hold my main thread until the second thread closed the dialog when it completed.
-
Apr 12th, 2011, 11:07 AM
#4
Re: [RESOLVED] Threading a progressbar
OK, cool. =)
And I wasn't really complaining or anything. I was just being colorful in linking you to another thread. =)
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
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
|