Page 1 of 1

"Wrong Thread" returned by AsyncDoAndWaitForFinish for op.document.addHeaderAndFooter

Posted: Tue Nov 17, 2020 1:53 pm
by zarkogajic
Hi Support,

I have a rather complex and strange problem happening when working with IOperation and AsyncDo[AndWaitForFinish]

Before trying to understand what's really going bad, can you please shed some light on why would AsyncDoAndWaitForFinish raise "Wrong Thread" ?

Here's what I have - and I'll try to make it as simple as possible:

- I have my class "MyOp" implementing IOperation
- I have a list of MyOp instances
- I'm using Inst.AsyncDo to "execute" MyOp's (called for each my op instance in the list)
- Inside the MyOp.Do() method:
== OpenDocumentFromFile to get a CoreDocument::IPXC_Document
== do some stuff with CoreDocument (like Set OpenActions and alike)
== placing headers footers (this is where the problems happen)

I've tried using op.document.addHeaderAndFooter and what happens for some MyOp instances is that the code does not go pass IOperation(op.document.addHeaderAndFooter).Do(). No exceptions raised, simply "spins" and never finishes.

Note that the above call is actually happening inside the Do method of MyOp class implementing IOperation being run inside a different thread (already) since called via AsyncDo.

So, yes I'm trying to execute an IOperation(op.document.addHeaderAndFooter) inside MyOp's.IOperation.Do method.

What I then tried is executing IOperation(op.document.addHeaderAndFooter).Do() via AsyncDoAndWaitForFinish - the result is an exception "Wrong Thread".

Why?

p.s.
I hope the above is clear enough, if not here's some pseudo-code:

Code: Select all

//pseudo code

MyClass.IOperation.Do method
{
	coreDoc = InstPXC.OpenDocumentFromFile
	coreDoc.Props.OpenActions = null //just to do something with coreDoc

	//and now the problematic part!
	op = Inst.CreateOp(op.document.addHeaderAndFooter)
	op.Do()
	//THIS LINE IS NEVER REACHED *SOMETIMES* (randomly for some MyClass instances)
	
	//IF tried like this
	Inst.AsyncDoAndWaitForFinish(op)	//-> raises "Wrong Thread"
}
-žarko

Re: "Wrong Thread" returned by AsyncDoAndWaitForFinish for op.document.addHeaderAndFooter

Posted: Tue Nov 17, 2020 2:34 pm
by Sasha - PDF-XChange
Hello zarkogajic,

If the operation itself is being executed in separate thread, then you cannot use the AsyncDoAndWaitForFinish from the inside as it's only meant to be used from the main thread.

Cheers,
Alex

Re: "Wrong Thread" returned by AsyncDoAndWaitForFinish for op.document.addHeaderAndFooter

Posted: Tue Nov 17, 2020 2:51 pm
by zarkogajic
Hi Alex,

Thanks, I thought that's the case. Ok, so, my original problem is still there, though...

Could you look inside your code for the operation "op.document.addHeaderAndFooter" - what could cause the Do() method never to return?

Btw, this issue is probably related to: https://forum.pdf-xchange.com/viewtopic.php?f=66&t=35246

(if it helps: the same problem happens with addWatermark operation - does not finish for some files)


-žarko

Re: "Wrong Thread" returned by AsyncDoAndWaitForFinish for op.document.addHeaderAndFooter  SOLVED

Posted: Wed Nov 18, 2020 6:25 pm
by zarkogajic
Hi Support,

Since this is what's happening:

https://forum.pdf-xchange.com/viewtopic.php?f=66&t=35246

I'll "close" this topic here.


"Wrong Thread" returned by AsyncDoAndWaitForFinish for op.document.addHeaderAndFooter

Posted: Thu Nov 19, 2020 7:26 am
by Sasha - PDF-XChange
:)