mirror of
https://github.com/cyanfish/naps2.git
synced 2024-09-21 12:49:43 +03:00
Use Task.Run instead of Task.Factory.StartNew
Fingers crossed that using the actual .NET task implementation will resolve the issues that required LongRunning.
This commit is contained in:
parent
69b6219670
commit
4b8a5d2af9
@ -47,7 +47,7 @@ namespace NAPS2.ClientServer
|
||||
throw new InvalidOperationException("ScanProfile.ProxyConfig must be specified to use ProxiedScanDriver.");
|
||||
}
|
||||
|
||||
return Task.Factory.StartNew(async () =>
|
||||
return Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -120,7 +120,7 @@ namespace NAPS2.ClientServer
|
||||
{
|
||||
Log.ErrorException("Error scanning with proxy", e);
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning).Unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ namespace NAPS2.ImportExport.Pdf
|
||||
|
||||
public override async Task<bool> Export(string path, ICollection<ScannedImage.Snapshot> snapshots, PdfSettings settings, OcrContext ocrContext, ProgressHandler progressCallback, CancellationToken cancelToken)
|
||||
{
|
||||
return await Task.Factory.StartNew(() =>
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
var forced = AppConfig.Current.ForcePdfCompat;
|
||||
var compat = forced == PdfCompat.Default ? settings.Compat : forced;
|
||||
@ -129,7 +129,7 @@ namespace NAPS2.ImportExport.Pdf
|
||||
PathHelper.EnsureParentDirExists(path);
|
||||
document.Save(path);
|
||||
return true;
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
});
|
||||
}
|
||||
|
||||
private bool BuildDocumentWithoutOcr(ProgressHandler progressCallback, CancellationToken cancelToken, PdfDocument document, PdfCompat compat, ICollection<ScannedImage.Snapshot> snapshots)
|
||||
|
@ -41,7 +41,7 @@ namespace NAPS2.ImportExport.Pdf
|
||||
public ScannedImageSource Import(string filePath, ImportParams importParams, ProgressHandler progressCallback, CancellationToken cancelToken)
|
||||
{
|
||||
var sink = new ScannedImageSink();
|
||||
Task.Factory.StartNew(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (cancelToken.IsCancellationRequested)
|
||||
{
|
||||
@ -110,7 +110,7 @@ namespace NAPS2.ImportExport.Pdf
|
||||
{
|
||||
sink.SetCompleted();
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
});
|
||||
return sink.AsSource();
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ namespace NAPS2.ImportExport
|
||||
}
|
||||
|
||||
var snapshots = imagesToPrint.Select(x => x.Preserve()).ToList();
|
||||
return await Task.Factory.StartNew(() =>
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -121,7 +121,7 @@ namespace NAPS2.ImportExport
|
||||
{
|
||||
snapshots.ForEach(s => s.Dispose());
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ namespace NAPS2.Scan.Batch
|
||||
|
||||
private async Task Input()
|
||||
{
|
||||
await Task.Factory.StartNew(async () =>
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
scans = new List<List<ScannedImage>>();
|
||||
|
||||
@ -163,7 +163,7 @@ namespace NAPS2.Scan.Batch
|
||||
CancelToken.ThrowIfCancellationRequested();
|
||||
} while (PromptForNextScan());
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning).Unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
private void ThreadSleepWithCancel(TimeSpan sleepDuration, CancellationToken cancelToken)
|
||||
|
@ -221,7 +221,7 @@ namespace NAPS2.Scan.Sane
|
||||
|
||||
private async Task<(ScannedImage, bool)> Transfer(Lazy<KeyValueScanOptions> options, int pageNumber, ScanProfile scanProfile, ScanParams scanParams, ScanDevice scanDevice, CancellationToken cancelToken)
|
||||
{
|
||||
return await Task.Factory.StartNew(() =>
|
||||
return await Task.Run(() =>
|
||||
{
|
||||
Stream stream;
|
||||
if (scanParams.NoUI)
|
||||
@ -272,7 +272,7 @@ namespace NAPS2.Scan.Sane
|
||||
return (image, false);
|
||||
}
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ namespace NAPS2.Scan
|
||||
}
|
||||
|
||||
var sink = new ScannedImageSink();
|
||||
Task.Factory.StartNew(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
ScanDriverException error = null;
|
||||
try
|
||||
@ -168,7 +168,7 @@ namespace NAPS2.Scan
|
||||
sink.SetCompleted();
|
||||
}
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
});
|
||||
return AutoSave(sink, scanParams, scanProfile);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace NAPS2.Scan.Twain
|
||||
|
||||
protected override async Task ScanInternal(ScannedImageSink sink, ScanDevice scanDevice, ScanProfile scanProfile, ScanParams scanParams, IntPtr dialogParent, CancellationToken cancelToken)
|
||||
{
|
||||
await Task.Factory.StartNew(async () =>
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
if (UseWorker(scanProfile))
|
||||
{
|
||||
@ -76,7 +76,7 @@ namespace NAPS2.Scan.Twain
|
||||
{
|
||||
twainWrapper.Scan(dialogParent, scanDevice, scanProfile, scanParams, cancelToken, sink, scannedImageHelper.RunBackgroundOcr);
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning).Unwrap();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ namespace NAPS2.WinForms
|
||||
|
||||
private void FScanProgress_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Task.Factory.StartNew(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -91,7 +91,7 @@ namespace NAPS2.WinForms
|
||||
DialogResult = CancelToken.IsCancellationRequested ? DialogResult.Cancel : DialogResult.OK;
|
||||
Close();
|
||||
});
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
});
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
|
Loading…
Reference in New Issue
Block a user