Results 1 to 4 of 4

Thread: [RESOLVED] Threading a progressbar

  1. #1

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Resolved [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.

  2. #2
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    Re: Threading a progressbar

    Objection Your Honor: Asked and Answered!

    http://www.vbforums.com/showthread.php?t=644769
    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)

  3. #3

    Thread Starter
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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.

  4. #4
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    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
  •  



Click Here to Expand Forum to Full Width