xunkong / KeqingNiuza

刻记牛杂店
MIT License
517 stars 53 forks source link

求适配win7 #23

Closed wuguxi5 closed 2 years ago

Scighost commented 2 years ago

win7需要安装.NET Framework 4.8运行时,然后就可以运行; 下面两个功能因为用到了win10的系统通知,会有一些问题: 任务提醒:我没有做捕获异常,在win7上会闪退; 米游社签到:不会有通知提醒; 其他功能应该不会受系统影响。

wuguxi5 commented 2 years ago

好的,谢谢

wuguxi5 commented 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.d39.MoveNext() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\MainWindow.xaml.cs:行号 336 --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 KeqingNiuza.Launcher.MainWindow.d38.MoveNext() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\MainWindow.xaml.cs:行号 300 --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 KeqingNiuza.Launcher.MainWindow.d__36.MoveNext() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\MainWindow.xaml.cs:行号 237 --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 在 System.Windows.Threading.DispatcherOperation.InvokeImpl() 在 MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Windows.Threading.DispatcherOperation.Invoke() 在 System.Windows.Threading.Dispatcher.ProcessQueue() 在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 在 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 在 System.Windows.Application.RunDispatcher(Object ignore) 在 System.Windows.Application.RunInternal(Window window) 在 KeqingNiuza.Launcher.App.Main() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\obj\Release\App.g.cs:行号 52

[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.d39.MoveNext() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\MainWindow.xaml.cs:行号 336 --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 KeqingNiuza.Launcher.MainWindow.d38.MoveNext() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\MainWindow.xaml.cs:行号 300 --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 KeqingNiuza.Launcher.MainWindow.d__36.MoveNext() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\MainWindow.xaml.cs:行号 237 --- 引发异常的上一位置中堆栈跟踪的末尾 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 在 System.Windows.Threading.DispatcherOperation.InvokeImpl() 在 MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Windows.Threading.DispatcherOperation.Invoke() 在 System.Windows.Threading.Dispatcher.ProcessQueue() 在 System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 在 MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 在 MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 在 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs) 在 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 在 MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 在 System.Windows.Application.RunDispatcher(Object ignore) 在 System.Windows.Application.RunInternal(Window window) 在 KeqingNiuza.Launcher.App.Main() 位置 D:\a\KeqingNiuza\KeqingNiuza\src\KeqingNiuza.Launcher\obj\Release\App.g.cs:行号 52

wuguxi5 commented 2 years ago

启动器无法打开软件本体,但是从bin目录打开exe可以,以上为日志内容

Lightczx commented 2 years ago

https://github.com/Scighost/KeqingNiuza/blob/main/src/KeqingNiuza.Launcher/MainWindow.xaml.cs#336

Scighost commented 2 years ago

你这个问题挺有意思,文档上提到了没有TaskCanceledException异常,但你又的确碰到了。 可能是网络问题,试一试这个检查更新的网页能不能打开。

Lightczx commented 2 years ago

你这个问题挺有意思,文档上提到了没有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的 微软的文档不能全信

Lightczx commented 2 years ago
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;
}
wuguxi5 commented 2 years ago

你这个问题挺有意思,文档上提到了没有TaskCanceledException异常,但你又的确碰到了。 可能是网络问题,试一试这个检查更新的网页能不能打开。

能打开

Scighost commented 2 years ago

修复了「已取消一个任务」时的闪退,但是不能保证正常更新。