Solved

How do I catch printing errors in a .Net Winforms control hosted in a WPF application?

Posted on 2013-06-25
2
499 Views
Last Modified: 2013-06-26
Hi:

I have a WPF application, which hosts a custom control which wraps a 3rd party (DevExpress) winforms control.

From within the DevExpress control, I can print using (what I believe is the standard winforms printing dialog). It prints successfully.

However, if there are issues with the printer (not found, connected, turned on or in error state), I do not get notification of that error.
How do I catch these errors?
Are exceptions getting thrown somewhere that I am unaware of?

The client/users/customers would like to be notified of such states/conditions/errors.

Thanks,
JohnB
0
Comment
Question by:jxbma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39277120
this is the basic code i'm using to detect print jobs which their status is not OK.
basically whenever a print job is arraived, the event handler loop through the job PropertyData which store all the print job properties.
i can use this information to detect which job failed, what document was it, what kind of error, printer name and so on.
CreatePrintJobsWatcher, creates the event watcher on Win32_PrintJob, and objWatcher_EventArrived is the event handler which processes the data.

      static void Main(string[] args)
        {
            CreatePrintJobsWatcher();
            Console.ReadLine();
        }

        private static void CreatePrintJobsWatcher()
        {
            var objWatcher = new ManagementEventWatcher();
            objWatcher.Query = new EventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_PrintJob'");
            objWatcher.Scope = new ManagementScope("\\root\\cimv2");
            objWatcher.Start();
            objWatcher.EventArrived += new EventArrivedEventHandler(objWatcher_EventArrived);
        }

        static void objWatcher_EventArrived(object sender, EventArrivedEventArgs e)
        {
            ManagementBaseObject job = (ManagementBaseObject)e.NewEvent.Properties["TargetInstance"].Value;
            foreach (PropertyData p in job.Properties)
            {
                try
                {
                    Console.WriteLine(p.Name + " : " + p.Value.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine(p.Name + " : Unknown");
                }
            }
        }

Open in new window

0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 39280257
Spot on. Thanks for the quick response.
0

Featured Post

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question