lukevp / ESC-POS-.NET

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

2.0.0 does not disconnect on disposing NetworkPrinter #169

Closed AertsIT closed 1 year ago

AertsIT commented 2 years ago

When disposing the NetworkPrinter, it looks like the connection is not terminated.

gusVLZ commented 2 years ago

I had the same issue, the application printed once and stopped working, the solution was to implement a Singleton architecture to maintain the same connection with the printer, it solved for me

orbitasol commented 2 years ago

Hi @gusVLZ I am facing the exact same problem as you and would like to know if you can share a sample code of your solution. Please note that I am using the library in an Asp.net Core 5 MVC project. Thanks in advance.

lukevp commented 1 year ago

Give the new ImmediateNetworkPrinter a try in release 3.0.0 @AertsIT @orbitasol , it does not have these issues with repeated disposals. The NetworkPrinter implementation in 2.0 was meant to be a singleton for the lifetime of your application, as it handles reconnecting internally, which is what Gus recommended. The ImmediateNetworkPrinter is simpler to use, but it loses the status functionality that the singleton approach has.