Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Conceição <Tiago_caza@hotmail.com>2021-08-31 19:06:46 +0300
committerTiago Conceição <Tiago_caza@hotmail.com>2021-08-31 19:06:46 +0300
commit774fe9d5d096aa2922f2219ddfeeb18c925530de (patch)
treea989b30e4119a10d7f56e97d54240ad8849e83da /UVtools.WPF/UserSettings.cs
parent1fd53c9d3c34ef2e4027eb2ceb8e79d9e6cdb7e3 (diff)
v2.20.5v2.20.5
- (Add) Setting - Max degree of parallelism: Sets the maximum number of concurrent tasks/threads/operations enabled to run by parallel method calls. If your computer lags and freeze during operations you can reduce this number to reduce the workload and keep some cores available to other tasks as well. <= 0: Will utilize however many threads the underlying scheduler provides, mostly this is the processor count. 1: Single thread. (#279)
Diffstat (limited to 'UVtools.WPF/UserSettings.cs')
-rw-r--r--UVtools.WPF/UserSettings.cs46
1 files changed, 28 insertions, 18 deletions
diff --git a/UVtools.WPF/UserSettings.cs b/UVtools.WPF/UserSettings.cs
index 2ac29c6..b76150e 100644
--- a/UVtools.WPF/UserSettings.cs
+++ b/UVtools.WPF/UserSettings.cs
@@ -9,6 +9,7 @@
using System;
using System.Diagnostics;
using System.IO;
+using System.Threading.Tasks;
using System.Xml.Serialization;
using Avalonia.Media;
using JetBrains.Annotations;
@@ -22,7 +23,7 @@ namespace UVtools.WPF
public sealed class UserSettings : BindableBase
{
#region Constants
- public const ushort SETTINGS_VERSION = 4;
+ public const ushort SETTINGS_VERSION = 5;
#endregion
#region Sub classes
@@ -34,6 +35,8 @@ namespace UVtools.WPF
private bool _startMaximized = true;
private bool _checkForUpdatesOnStartup = true;
private bool _loadDemoFileOnStartup = true;
+ private int _maxDegreeOfParallelism = -1;
+
private bool _windowsCanResize;
private bool _windowsTakeIntoAccountScreenScaling = true;
private ushort _windowsHorizontalMargin = 100;
@@ -48,7 +51,6 @@ namespace UVtools.WPF
private bool _promptOverwriteFileSave = true;
private string _fileSaveNamePrefix;
private string _fileSaveNameSuffix = "_copy";
- private int _maxDegreeOfParallelism;
public bool StartMaximized
@@ -69,6 +71,15 @@ namespace UVtools.WPF
set => RaiseAndSetIfChanged(ref _loadDemoFileOnStartup, value);
}
+ /// <summary>
+ /// Gets or sets the maximum number of concurrent tasks enabled by a ParallelOptions instance.
+ /// </summary>
+ public int MaxDegreeOfParallelism
+ {
+ get => _maxDegreeOfParallelism;
+ set => RaiseAndSetIfChanged(ref _maxDegreeOfParallelism, Math.Min(value, Environment.ProcessorCount));
+ }
+
public bool WindowsCanResize
{
get => _windowsCanResize;
@@ -154,19 +165,7 @@ namespace UVtools.WPF
set => RaiseAndSetIfChanged(ref _fileSaveNameSuffix, value);
}
- /// <summary>
- /// Gets or sets the maximum number of concurrent tasks enabled by a ParallelOptions instance.
- /// </summary>
- public int MaxDegreeOfParallelism
- {
- get => _maxDegreeOfParallelism;
- set => RaiseAndSetIfChanged(ref _maxDegreeOfParallelism, value);
- }
-
- public GeneralUserSettings()
- {
- MaxDegreeOfParallelism = Environment.ProcessorCount;
- }
+ public GeneralUserSettings() { }
public GeneralUserSettings Clone()
{
@@ -1417,16 +1416,26 @@ namespace UVtools.WPF
using var myXmlReader = new StreamReader(FilePath);
_instance = (UserSettings)serializer.Deserialize(myXmlReader);
if (_instance.General.MaxDegreeOfParallelism <= 0)
- _instance.General.MaxDegreeOfParallelism = Environment.ProcessorCount;
+ {
+ _instance.General.MaxDegreeOfParallelism = -1;
+ }
+ else
+ {
+ _instance.General.MaxDegreeOfParallelism = Math.Min(_instance.General.MaxDegreeOfParallelism, Environment.ProcessorCount);
+ }
+
if (_instance.SettingsVersion < SETTINGS_VERSION)
{
// Upgrade
-
+ if (_instance.SettingsVersion <= 4)
+ {
+ _instance.General.MaxDegreeOfParallelism = -1;
+ }
_instance.SettingsVersion = SETTINGS_VERSION;
}
-
+ CoreSettings.MaxDegreeOfParallelism = _instance.General.MaxDegreeOfParallelism;
}
catch (Exception e)
{
@@ -1443,6 +1452,7 @@ namespace UVtools.WPF
{
Instance.SavesCount++;
_instance.ModifiedDateTime = DateTime.Now;
+ CoreSettings.MaxDegreeOfParallelism = _instance.General.MaxDegreeOfParallelism;
var serializer = new XmlSerializer(_instance.GetType());
try
{