Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-06-25
2
Medium Priority
?
504 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:
Meir Rivkin earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

597 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