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?