lukevp / ESC-POS-.NET

Efficient, Easy to Use Thermal Printing & POS (Windows/Linux/OSX, WiFi/BT/USB/Ethernet)
MIT License
523 stars 171 forks source link

BasePrinter Dispose() method block printing #218

Open emanuhell opened 1 year ago

emanuhell commented 1 year ago

BasePrinter Dispose() method block printing. For example:

printer.Write(e.Initialize());
printer.Write(e.Enable());
printer.Write(Tests.Receipt(e));
printer.Dispose();

prints nothing! I need the Dispose method to release the connection to the printer after each print, to allow other running applications to use the same printer. Thanks.

lukevp commented 1 year ago

Which printer are you using? Some of the implementations are asynchronous (Writes are buffered and flushed by a task). This is to increase the performance of many small writes. You may just be disposing the connection before the flush happens. We should probably expose a way to await the print queue being empty.

emanuhell commented 1 year ago

Which printer are you using? I'm using the SerialPrinter.

We should probably expose a way to await the print queue being empty. What method are you talking about? I can't find it.

Thanks.

mtarlac commented 1 month ago

Sorry for digging this up but what is the difference between version 1.6 (which works fine) and 3.0?

After it prints the first time, I'm facing an error

System.IO.IOException: Device or resource busy : '/dev/usb/lp3'

I tried both options

var printerLinUsb = new FilePrinter(filePath: '/dev/usb/lp3'`, false);
...
printerLinUsb.Dispose();

and

using (var printerLinUsb = new FilePrinter(filePath: '/dev/usb/lp3'`, false))
{
...
}