I have designed a system that is made up of 3 separate applications:
- Web Application
- WCF Service application that receives requests from the web app, does the appropriate action and prints the result using the SendKeys class
SendKeys.SendWait("^p");
(this send a Ctrl + P command that prints whats on the screen). - Console application that intercepts printer output (virtual printer via redmon) via the Console.In (as suggested here
The WCF Service app and Web application can communicate easily, but there is no direct communication between the service app and console application. The console app only starts when there is a printer job and the WCF app doesn't know the result of the print job.
Is there a way to make the WCF Service app recieve feedback from the printed job (whether it was ok or not), so it can send appropriate response back to the web application, without doing Thread.Sleep()
each second until the printer app finishes printing and saves the result in a file or database?
Is there a way i could pause the thread in the WCF service app, and resume it (whilst sending information back) from the printer console application when the printing process is done?
Edit:
I managed to find a solution from Richard Blewett's suggestions. The solution would make the WCF service app wait untill the print job is finnished, but it will cause the WCF app to be limited to only making one print job at a time.
I create an EventWaitHandle with some key in the WCF app like this:
EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.ManualReset, "unique-key");
WaitHandle.WaitAny(new WaitHandle[] { ewh });
And i can return to the thread from the Console app like this:
EventWaitHandle ewh = EventWaitHandle.OpenExisting("unique-key");
ewh.Set();
With Richard's solution this will not be the case, and multiple WCF service calls can be done simultaneously.