问题
We have an older WPF application that makes use of the "Windows API Code Pack" in order to show a Task Dialog (something that was introduced back in Vista but worked all the way through Windows 8).
I'm now trying to run the project on Windows 10, and when I try to show the Task Dialog, I get the following exception:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.WindowsAPICodePack.Dialogs.TaskDialogNativeMethods.TaskDialogIndirect (TaskDialogConfiguration taskConfig, Int32& button, Int32& radioButton, Boolean& verificationFlagChecked)
at Microsoft.WindowsAPICodePack.Dialogs.NativeTaskDialog.NativeShow()
at Microsoft.WindowsAPICodePack.Dialogs.TaskDialog.ShowCore()
Are these APIs no longer available in Windows 10?
Is there a replacement with similar functionality that is available in Windows 10 without writing a custom dialog?
Edit: I got it to run (sheer luck I guess? I didn't change any code) and the dialog popped up like this:
There should be 3 buttons, and definitely no Chinese characters, so I would agree with the exception that there is definitely some memory issue going on here. Any ideas?
回答1:
The Task Dialog is still supported in Windows 10, but the problem is likely this issue in the library that you seem to be using: https://github.com/aybe/Windows-API-Code-Pack-1.1/issues/3
As noted in the issue description, it can cause the AccessViolationException
(and probably the incorrect characters) on 64-bit Windows. You can fix it by applying the changes from the referenced pull request.
Note: There is a request to include an official Task Dialog implementation in future .NET Core versions now that WinForms is open source: https://github.com/dotnet/winforms/issues/146
来源:https://stackoverflow.com/questions/46838210/taskdialog-not-working-on-or-replacement-for-windows-10