*
This commit is contained in:
1 parent
a1fcb5241a
commit
d3daf1988f
2 files changed
+8
-8
No files matched your search
@@ -178,7 +178,7 @@ public abstract class RedoableWorkerBase<TOut>(Func<CancellationToken?, Progress
|
|||||||
(_, timedOut) => completionSource.TrySetResult(!timedOut), null, millisecondsTimeout, executeOnlyOnce: true);
|
(_, timedOut) => completionSource.TrySetResult(!timedOut), null, millisecondsTimeout, executeOnlyOnce: true);
|
||||||
using var cancellationRegistration = cancellationToken.Register(() => completionSource.TrySetCanceled(cancellationToken));
|
using var cancellationRegistration = cancellationToken.Register(() => completionSource.TrySetCanceled(cancellationToken));
|
||||||
try {
|
try {
|
||||||
return await completionSource.Task;
|
return await completionSource.Task.NoCapture();
|
||||||
} finally {
|
} finally {
|
||||||
waitHandle.Unregister(null);
|
waitHandle.Unregister(null);
|
||||||
}
|
}
|
||||||
@@ -207,4 +207,4 @@ public class RedoableWorker : RedoableWorkerBase<NoType?> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>指示没有该类型,用于泛型参数。</summary>
|
/// <summary>指示没有该类型,用于泛型参数。</summary>
|
||||||
public class NoType { }
|
public class NoType { }
|
||||||
@@ -16,7 +16,7 @@ public static class TaskUtils {
|
|||||||
var progressEach = 1d / taskList.Count;
|
var progressEach = 1d / taskList.Count;
|
||||||
return Task.WhenAll(taskList.Select(async (task, index) => {
|
return Task.WhenAll(taskList.Select(async (task, index) => {
|
||||||
var cp = progress?.SplitBy(progressEach)[0];
|
var cp = progress?.SplitBy(progressEach)[0];
|
||||||
await task(cp).ConfigureAwait(false);
|
await task(cp).NoCapture();
|
||||||
cp?.Finish();
|
cp?.Finish();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ public static class TaskUtils {
|
|||||||
var progressEach = 1d / taskList.Count;
|
var progressEach = 1d / taskList.Count;
|
||||||
return Task.WhenAll(taskList.Select(async (task, index) => {
|
return Task.WhenAll(taskList.Select(async (task, index) => {
|
||||||
var cp = progress?.SplitBy(progressEach)[0];
|
var cp = progress?.SplitBy(progressEach)[0];
|
||||||
var result = await task(cp).ConfigureAwait(false);
|
var result = await task(cp).NoCapture();
|
||||||
cp?.Finish();
|
cp?.Finish();
|
||||||
return result;
|
return result;
|
||||||
}));
|
}));
|
||||||
@@ -66,7 +66,7 @@ public static class TaskUtils {
|
|||||||
if (!enumerator.MoveNext()) return;
|
if (!enumerator.MoveNext()) return;
|
||||||
item = enumerator.Current;
|
item = enumerator.Current;
|
||||||
}
|
}
|
||||||
await body(item, cp).ConfigureAwait(false);
|
await body(item, cp).NoCapture();
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
try {
|
try {
|
||||||
@@ -76,7 +76,7 @@ public static class TaskUtils {
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await TaskUtils.WhenAll(Enumerable.Repeat(WorkerAsync, maxDegreeOfParallelism), progress).ConfigureAwait(false);
|
await TaskUtils.WhenAll(Enumerable.Repeat(WorkerAsync, maxDegreeOfParallelism), progress).NoCapture();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -110,7 +110,7 @@ public static class TaskUtils {
|
|||||||
var timeoutTask = Task.Delay(hasTimeout ? timeoutMs!.Value : Timeout.Infinite);
|
var timeoutTask = Task.Delay(hasTimeout ? timeoutMs!.Value : Timeout.Infinite);
|
||||||
var cancelTask = Task.Delay(Timeout.Infinite, cancellationToken);
|
var cancelTask = Task.Delay(Timeout.Infinite, cancellationToken);
|
||||||
Logger.Trace($"等待程序 {program.Id} 完成");
|
Logger.Trace($"等待程序 {program.Id} 完成");
|
||||||
var completedTask = await Task.WhenAny(task, timeoutTask, cancelTask);
|
var completedTask = await Task.WhenAny(task, timeoutTask, cancelTask).NoCapture();
|
||||||
if (completedTask != task) {
|
if (completedTask != task) {
|
||||||
try {
|
try {
|
||||||
if (!program.HasExited) program.Kill();
|
if (!program.HasExited) program.Kill();
|
||||||
@@ -119,7 +119,7 @@ public static class TaskUtils {
|
|||||||
if (completedTask == cancelTask) throw new OperationCanceledException(cancellationToken);
|
if (completedTask == cancelTask) throw new OperationCanceledException(cancellationToken);
|
||||||
throw new TimeoutException($"运行程序超时:{file} {arguments}");
|
throw new TimeoutException($"运行程序超时:{file} {arguments}");
|
||||||
}
|
}
|
||||||
return (await outputTask + await errorTask, program.ExitCode);
|
return (await outputTask.NoCapture() + await errorTask.NoCapture(), program.ExitCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user