1

I want to cancel a specific print job in a print queue by it's job info but when the program run cancelling code gots an error

The calling thread cannot access this object because a different thread owns it.

the code is here :

 void pqm_OnJobStatusChange(object Sender, PrintJobChangeEventArgs e)
    {
        MethodInvoker invoker = () =>
        {
            PrintSystemJobInfo t = e.JobInfo;
            printevent temp = new printevent(e);
            lbSpoolChanges.Items.Add(e.JobID+"  "+e.JobName);
            if (temp.getName().Contains("a.docx")){


                    t.Cancel();//caused error!!!!!
                lbSpoolChanges.Items.Add("Detected");
            }

        };
        if (lbSpoolChanges.InvokeRequired)
        {
            Invoke(invoker);
        }
        else
        {
            invoker();
        }

    }

could you help me?

  • Possible duplicate of [The calling thread cannot access this object because a different thread owns it](http://stackoverflow.com/questions/9732709/the-calling-thread-cannot-access-this-object-because-a-different-thread-owns-it) – Nick Westgate Jul 20 '16 at 10:20

0 Answers0