Reputation: 3632
I've read a few other questions that seem similar but I'm still very confused, and none of the answers seem to be working for me so I decided to ask another question. Please bear with me, I'm not very well versed on threading and what not.
The application I am making is a 3rd party add-in for Revit Structure. The way they work is I hae a class library with a class that implements an interface, when that is called my application runs.
My tool is a Printing tool, it aims to automate printing to a PDF. I am trying to move my code over to using PdfCreator to print the PDFs (the way printing works in Revit is you set the printer and call the 'print' method in the API, so I can't do PDFs any way other than through a printer).
PDFCreator has a great COM interface that allows you to set its settings, as well as subscribing to an event which fires after every document is printed. I'm calling hte print method multiple times, so I want to wait until all are done, then do something in my code.
My logic goes like this:
My problem is, that when I call the print method, my code doesn't wait for the PDFcreator events, it just continues through and exits, which means the post processing is never fired.
What I need to do is somehow wait for the event, without blocking.
After reading some other questions I've tried this:
how do I make the event fire on a new thread and then alert the current thread to keep going? Or how can I make the code wait for the event to fire ?
Let me know if you need any more info, happy to provide.
Upvotes: 2
Views: 889
Reputation: 170509
Your problem is the following. That other library needs a running message loop to be able to fire the event. Specifically when a certain message arrives from the message loop that message is dispatched into the library and causes it to fire the event.
If you use some "wait" primitive in your calling code you block the message loop and thus the event is never fired. Your program should not block - it should continue running the message loop like every Windows GUI program does.
Upvotes: 1