mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-13 02:12:59 +00:00
@@ -1,5 +1,6 @@
|
||||
using DiscordChatExporter.Core.Services;
|
||||
using DiscordChatExporter.Gui.ViewModels.Framework;
|
||||
using Tyrrrz.Extensions;
|
||||
|
||||
namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||
{
|
||||
@@ -25,6 +26,12 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
|
||||
set => _settingsService.IsTokenPersisted = value;
|
||||
}
|
||||
|
||||
public int ParallelLimit
|
||||
{
|
||||
get => _settingsService.ParallelLimit;
|
||||
set => _settingsService.ParallelLimit = value.Clamp(1, 10);
|
||||
}
|
||||
|
||||
public SettingsViewModel(SettingsService settingsService)
|
||||
{
|
||||
_settingsService = settingsService;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordChatExporter.Core.Models;
|
||||
using DiscordChatExporter.Core.Models.Exceptions;
|
||||
@@ -260,10 +261,13 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
|
||||
// Export channels
|
||||
var successfulExportCount = 0;
|
||||
for (var i = 0; i < dialog.Channels.Count; i++)
|
||||
using var semaphore = new SemaphoreSlim(_settingsService.ParallelLimit.ClampMin(1));
|
||||
|
||||
await Task.WhenAll(dialog.Channels.Select(async (channel, i) =>
|
||||
{
|
||||
var operation = operations[i];
|
||||
var channel = dialog.Channels[i];
|
||||
|
||||
await semaphore.WaitAsync();
|
||||
|
||||
try
|
||||
{
|
||||
@@ -288,8 +292,9 @@ namespace DiscordChatExporter.Gui.ViewModels
|
||||
finally
|
||||
{
|
||||
operation.Dispose();
|
||||
semaphore.Release();
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
// Notify of overall completion
|
||||
if (successfulExportCount > 0)
|
||||
|
||||
Reference in New Issue
Block a user