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

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

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

Post 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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

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

Post by Sasha - Tracker Dev Team »

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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

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

Post 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
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

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

Post 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.

Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

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

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply