Ejemplo n.º 1
0
 DataLoadingResult StartDownload(DataTaskComplited OnComplete, IDataLoader loader, IDataLoadTaskData data)
 {
     DataLoadingResult result = DataLoadingResult.LoaderErr;
     var ts = CancellationTokenSource.CreateLinkedTokenSource(Core.Core.globalCTS.Token, data.Token);
     foreach (var uri in data.Uri)
     {
         if (ts.IsCancellationRequested)
             return DataLoadingResult.Cancelled;
         result = loader.LoadMethod(uri, ts.Token, data.OnProcessCallback, 1024);
         if (result == DataLoadingResult.Ok || result == DataLoadingResult.Suspended || result == DataLoadingResult.Cancelled)
             break;
     }
     if (OnComplete != null && result != DataLoadingResult.Suspended && result != DataLoadingResult.LoaderErr && !Core.Core.globalCTS.IsCancellationRequested)
         OnComplete(data, result == DataLoadingResult.Ok ? TaskResult.Completed : result == DataLoadingResult.Cancelled ? TaskResult.Cancelled : TaskResult.Error);
     return result;
 }