I’m calling a print function from an external library and when the printer is out of paper the print sub hangs and everything freezes for 2 minutes.
Is there any way to call a sub with a timeout, let’s say, 3 seconds and after that the sub call is aborted?
I’ve tried with a timer but as soon as the sub call hangs, everything hang.
I'm I'm using a library called USBPrint that's in the forum and works ok with a ticket usb printer I've got on a project.
I'm using this code:
B4X:
Private usb_print As printdemo
usb_print.Initialize
usb_print.connectusb2(0x1233, 0x3221)
Dim msg As String = "Text to be printed"
usb_print.printdata(msg.GetBytes("UTF8"))
It works fine until the printer gets out of paper. When it does, that "printdata" call hangs and never stop making the whole program to freeze. I was trying to find a way to "stop" it.
I don't know how printdata is implemented. I guess that it does the worst thing that one can do with network communication and it tries to handle it with TextWriter instead of AsyncStreams.