How upload files to azure in background with Delphi and OmniThread? How upload files to azure in background with Delphi and OmniThread? azure azure

How upload files to azure in background with Delphi and OmniThread?


This blocks because you are calling WaitFor which waits for all pipeline stages to finish their work. During that wait, the GUI is blocked.

A proper way to do it is

  1. Store interface returned from Parallel.Pipeline in a global storage (for example in a TCloudManager field).
  2. Schedule work to the pipeline.
  3. Don't WaitFor end but assign OnStop handler and do whatever cleanup you need here (don't forget to nil out the global storage holding the pipeline interface).

To do step 3 you'll need fresh OmniThreadLibrary from the SVN because I just added this functionality :)

procedure TCloudManager.MassiveUpload(const BaseFolder: String;  Files: TDictionary<String, String>);var  FileInfo : TPair<String,String>;  FileTask:TFileTask;begin  // set up pipeline  FPipeline := Parallel.Pipeline    .Stage(UploadTask)      .NumTasks(Environment.Process.Affinity.Count * 2)    .OnStop(      procedure begin        ShowMessage('All done');        FPipeline := nil;      end)    .Run;//   insert URLs to be retrieved  for FileInfo in Files do  begin    FileTask.LocalFile := FileInfo.Key;    FileTask.CloudFile := FileInfo.Value;    FileTask.BaseFolder := BaseFolder;    FPipeline.Input.Add(TOmniValue.FromRecord(FileTask));  end;//for  FPipeline.Input.CompleteAdding;end;


Delphi has a .NET variant, right? Were you aware there's a .NET Managed API for the Azure Storage Service?

The CloudBlockBlob class has an async variant for upload/download, etc.

http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.windowsazure.storageclient.cloudblockblob_methods.aspx