Closed wuguxi5 closed 2 years ago
好的,谢谢
[2021-10-08 06:51:56.172 | Launcher 2.1.0]
System.Threading.Tasks.TaskCanceledException: 已取消一个任务。
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 KeqingNiuza.Launcher.MainWindow.
[2021-10-08 06:57:46.265 | Launcher 2.1.0]
System.Threading.Tasks.TaskCanceledException: 已取消一个任务。
在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
在 KeqingNiuza.Launcher.MainWindow.
启动器无法打开软件本体,但是从bin目录打开exe可以,以上为日志内容
你这个问题挺有意思,文档上提到了没有TaskCanceledException异常,但你又的确碰到了。 可能是网络问题,试一试这个检查更新的网页能不能打开。
GetByteArrayAsync
[__DynamicallyInvokable]
public Task<byte[]> GetByteArrayAsync(Uri requestUri)
{
return GetContentAsync(requestUri, HttpCompletionOption.ResponseContentRead, HttpUtilities.EmptyByteArray, (HttpContent content) => content.ReadAsByteArrayAsync());
}
GetContentAsync
private Task<T> GetContentAsync<T>(Uri requestUri, HttpCompletionOption completionOption, T defaultValue, Func<HttpContent, Task<T>> readAs) { TaskCompletionSource<T> tcs = new TaskCompletionSource<T>(); GetAsync(requestUri, completionOption).ContinueWithStandard(delegate(Task<HttpResponseMessage> requestTask) { if (!HandleRequestFaultsAndCancelation(requestTask, tcs)) { HttpResponseMessage result = requestTask.Result; if (result.Content == null) { tcs.TrySetResult(defaultValue); } else { try { readAs(result.Content).ContinueWithStandard(delegate(Task<T> contentTask) { if (!HttpUtilities.HandleFaultsAndCancelation(contentTask, tcs)) { tcs.TrySetResult(contentTask.Result); } }); } catch (Exception exception) { tcs.TrySetException(exception); } } } }); return tcs.Task; }
其中,此处可以引起任何异常
try { readAs(result.Content).ContinueWithStandard(delegate(Task<T> contentTask) { if (!HttpUtilities.HandleFaultsAndCancelation(contentTask, tcs)) { tcs.TrySetResult(contentTask.Result); } }); } catch (Exception exception) { tcs.TrySetException(exception); }
所以是有可能出现TaskCancelException的 微软的文档不能全信
internal static bool HandleFaultsAndCancelation<T>(Task task, TaskCompletionSource<T> tcs)
{
if (task.IsFaulted)
{
tcs.TrySetException(task.Exception.GetBaseException());
return true;
}
if (task.IsCanceled)
{
tcs.TrySetCanceled();
return true;
}
return false;
}
修复了「已取消一个任务」时的闪退,但是不能保证正常更新。
win7需要安装.NET Framework 4.8运行时,然后就可以运行; 下面两个功能因为用到了win10的系统通知,会有一些问题: 任务提醒:我没有做捕获异常,在win7上会闪退; 米游社签到:不会有通知提醒; 其他功能应该不会受系统影响。