Ejemplo n.º 1
0
 protected ActionBlock(bool ensureOrdered = false, int maxDegreeOfParallelism = 1)
 {
     _actionBlock = new System.Threading.Tasks.Dataflow.ActionBlock <TInput>(
         Act,
         new ExecutionDataflowBlockOptions
     {
         EnsureOrdered          = ensureOrdered,
         MaxDegreeOfParallelism = maxDegreeOfParallelism
     }
         );
 }
Ejemplo n.º 2
0
        public async Task MCDownload(List <string[]> urls, string instanceName, CancellationToken _ctsblock)
        {
            _cts = new CancellationTokenSource();
            int count = urls.Count;

            urlsList = urls;
            Dialogs.InstallModpack.singleton.filesToDownload.Content = "0" + "/" + urls.Count;
            if (urls != null && urls.Count != 0)
            {
                System.Net.ServicePointManager.DefaultConnectionLimit = Int32.Parse(Properties.Settings.Default["download_threads"].ToString());
                var block = new System.Threading.Tasks.Dataflow.ActionBlock <string[]>(async url =>
                {
                    try
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                        }));
                        await DownloadLibraries(url, instanceName);
                        //await ExtractForgeFiles(url);
                    }
                    catch (Exception e)
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() =>
                        {
                            Windows.DebugOutputConsole.singleton.Write("ERRORE IN" + url + "\r\n" + e);
                        }));
                        MessageBox.Show("ERRORE IN" + url + "\r\n" + e);
                    }
                }, new ExecutionDataflowBlockOptions {
                    MaxDegreeOfParallelism = Int32.Parse(Properties.Settings.Default["download_threads"].ToString()), CancellationToken = _ctsblock
                });

                foreach (var url in urls)
                {
                    block.Post(url);
                }
                block.Complete();
                try
                {
                    await block.Completion;
                }
                catch (TaskCanceledException)
                {
                    return;
                }
                Dialogs.InstallModpack.singleton.filesToDownload.Content   = urls.Count + "/" + urls.Count;
                Dialogs.InstallModpack.singleton.totalPercentage.Content   = "100%";
                Dialogs.InstallModpack.singleton.progressBarDownload.Value = 100;
            }
        }