What I Did:
Had to develop multiple threads in order to be able to handle multiple print requests in a Point Of Sale environment.
This was also necessary, since the printers would also pickup print requests from remote stations and one cannot freeze up the entire application that's running for transacting tables and items whilst working on it just because the printers are busy printing.
Therefore multithreading was definitely the solution to implement.
And for those who's wondering; No,you cannot use Windows to add the printer and try to give it print jobs.We use direct communication with a protocol called ESC/POS. Long story!
How I Did It:
A single station could support up to 8-locally attached slip/order printers which each are responsible for handling a specific print request.
A thread had to be coded for every possible printer that could be activated which has its own established connection to the database polling for new incoming print jobs. Since each thread has its own dedicated database connection and the logic is contained within the thread, one could continue interacting with the application itself without the application pausing or freezing up each time when a locally attached printer starts printing a requested print job.
- That multiple threads can have it's own dedicated database connection.
- That multiple threads should have it own database connection should you request or poll data from the database.
- That you can have as many printers attached to your station as you desire, as long as you know the comport settings and you have a thread for each active printer.
- Multiple multithreading can become pretty complex, but it is extremely useful and powerful.