WPF replication Exception Issue (OpenClipboard failure (Exception from hresult:0x800401d0 (Clipbrd_e_cant_open)))

Source: Internet
Author: User

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)))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.