views:

31

answers:

1

I have a WinForms app and am trying to add the ability to start up multiple operations based on data entered in a datagridview. The operations must be run synchronously to monitor that they complete succesfully before inserting a row into the DB to indicate that the operation was succesfull. I also have a status event handler on the operation which will return the percentage of the running operation.

So far I am using threads to kick off the operations, however it is updating the progress of just one of the threads. When that thread is complete it is moving on the the next and will work that until completion. I would like them both or more to run simultaneously and be able to report the status of each.

I am basically looping through the rows in the grid and using the values there to instantiate a new class I created. I am then creating a thread and kicking off a sub to perform the operation from the new object. I think I may be close as I know they are all being started, but they are just running one after the other rather than all at once.

Any help is appreciated.

+2  A: 

If they are running one after another, then it sounds like they are not running as threads. I suggest making sure your threads are running asynchronously.

Then when they do run at the same time, you can use delegates to report back to the main process and show your progress.

You can use this:

 Delegate Sub delShowProgressOne(ByVal Row As Integer, ByVal Percent As Double)
  Sub ShowProgressOne(ByVal Row As Integer, ByVal Percent As Double)
    If Me.InvokeRequired Then
      Me.Invoke(New delShowProgressOne(AddressOf ShowProgressOne), Row, Percent)
    Else
      DGV.Rows(Row).Cells("Progress").Value = Percent
    End If
  End Sub

To display the progress from within your thread. It sends the actual calling of the function to the Form's thread but only to do the ShowProgress.

Hope this information helps.

Jimmie Clark