Recently, in the maintenance of the WPF system, the problems found in the beginning of their own computer can not be reproduced, followed by log tracking to find out where the problem lies. The problem is mainly due to: 1.
When the program accesses the Clipboard, there are other programs that are occupying the Clipboard, causing their program to be inaccessible, thus throwing an exception; 2. There is no access permission, which causes your program to be inaccessible.
The following are the error details and the log trace exception detail:
This is the previous notation in the App.xaml.cs file:
#region
<summary>
Methods for handling Exceptions
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>
private void Application_dispatcherunhandledexception (object sender, Dispatcherunhandledexceptioneventargs e)
{
In WPF if replication does not have permissions at this point it will also come in here (PS: Run this program with administrator and compatibility OH)
if (E.exception.innerexception.message.contains ("network") | | e.exception.innerexception.message.contains ("timeout") | | e. Exception.InnerException.Message.Contains ("pause"))
{
Bugreport report = new Bugreport (e.exception);
Report. Save ();
E.handled = true;
Report. Launchbugreport ();
MessageBox.Show (E.exception.innerexception.message);
}
Else
{
Bugreport report = new Bugreport (e.exception);
Report. Save ();
Report. Launchbugreport ();
E.handled = true;
Application.Current.Shutdown ();
}
}
This is the modified wording:
Add the red part of the following code to the App.xaml file
Xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"
Startupuri= "MainWindow.xaml"
dispatcherunhandledexception= "Application_dispatcherunhandledexception" >
Add code in the App.xaml.cs file:
private void Application_dispatcherunhandledexception (object sender, Dispatcherunhandledexceptioneventargs e)
{
var comexception = e.exception As System.Runtime.InteropServices.COMException;
if (comexception! = null && Comexception.errorcode = = -2147221040)
e.handled = true;
bugreport report = new Bugreport (e.exception );
report. Save ();
e.handled = true;
}
In this way, the Clipboard action will be automatically repeated attempts, because the exception thrown by the app in the exception processing to intercept, so will continue to try until success. PS: Above is only a personal opinion, there is inappropriate, please correct me. Thank you! )
WPF replication Exception Issue (OpenClipboard failure (Exception from hresult:0x800401d0 (Clipbrd_e_cant_open)))