I am trying to configure uploading files to a server.
I would like to split the file into "n" chunks of size "y" each, and then upload the "x" chunks at a time to the server using streams. When one of the "x" blocks is complete, the other piece should start loading until there are no more pieces left to load.
I looked at BackgroundWorker and have the following implementation idea:
1) The next way to assign Worker.DoWork
private void ChunkUploaderDoWork(object sender, DoWorkEventArgs e) {
}
2) Then I can call
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (obj, e) => WorkerDoWork();
worker.ProgressChanged += new ProgressChangedEventHandler (Worker_ProgressChanged);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler (Worker_RunWorkerCompleted);
worker.RunWorkerAsync(argumentsList);
backgroundWorker , , , , . , , worker.RunWorkerAsync() ( , 4 ):
worker.RunWorkerAsync(argumentsListForChunk1);
worker.RunWorkerAsync(argumentsListForChunk2);
worker.RunWorkerAsync(argumentsListForChunk3);
worker.RunWorkerAsync(argumentsListForChunk4);
, - , :
void Worker_RunWorkerCompleted(object sender, ProgressChangedEventArgs e)
{
//Check if we have any outstanding chunks and upload next chunk if available.
//for example if we had chunk 5 next in line, then I could call RunWorkerAsync as follows:
worker.RunWorkerAsync(argumentsListForChunk5);
}
# , .
, ,
:)
Edit::
@o_weisman @HansPassant , .
, . , , , .
!