Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below code i have created the background process dynamically,My question is how to combine or Merger the datatable obtained from each of the background processes , Is there any way to make the below code work

What I have tried:

For Each value In intersect
                NumWorkers = NumWorkers + 1
                'MessageBox.Show(NumWorkers.ToString)
                ReDim Workers(NumWorkers)
                Workers(NumWorkers) = New BackgroundWorker
                Workers(NumWorkers).WorkerReportsProgress = True
                Workers(NumWorkers).WorkerSupportsCancellation = True
                AddHandler Workers(NumWorkers).DoWork, AddressOf WorkerDoWork
                Workers(NumWorkers).RunWorkerAsync(value)
                AddHandler Workers(NumWorkers).RunWorkerCompleted, AddressOf WorkerCompleted
            Next

 Private Sub WorkerDoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs)

         objclient.From_date = From_Date.Value.ToString("MM/dd/yyyy")
        objclient.To_date = To_Date.Value.ToString("MM/dd/yyyy")
        objclient.Connection_String = e.Argument
        ds = objclient.FileCompleted()
        ds.merger(ds)

    End Sub
Posted
Updated 11-Apr-18 7:21am
v5

1 solution

If I understand your question correctly, one quite brute-force way would be that you store the 'main' data table outside the background workers, perhaps in a static field.

In the end of each worker, use DataTable.Merge Method (System.Data)[^] to merge the data tables. Just remember to use SyncLock Statement | Microsoft Docs[^] to prevent simultaneous merge operations
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900