c# - System.Printing.PrintJobException: 'An exception occurred while setting the print job. Win32 error: The parameter i

时间: 2025-01-06 admin 业界

I am working on application where I need to monitor print jobs. It was working on WinForms example project, but not working in WPF project.

void pqm_OnJobStatusChange(object Sender, PrintJobChangeEventArgs e)
{
    try
    {
        PrintSystemJobInfo job = e.JobInfo;
        
        if (job == null) return;

        if (job.IsSpooling)
        {
            job.Pause(); // Getting error here
        }
        else if (job.IsPaused)
        {
            PrintQueue pq = job.HostingPrintQueue;
            pq.Refresh();

            if (JobDetails(printer, e.JobID))
            {
                job.Resume();
            }
            else
            {
                job.Cancel();
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

Error Exception:

System.Printing.PrintJobException: 'An exception occurred while setting the print job. Win32 error: The parameter is incorrect.