M mmanso Active Member Licensed User Longtime User Aug 13, 2021 #1 Hi all 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. thanks in advance.
Hi all 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. thanks in advance.
Erel B4X founder Staff member Licensed User Longtime User Aug 13, 2021 #2 No such thing. mmanso said: 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. Click to expand... Sounds like very bad code. Can you post it? Upvote 0
No such thing. mmanso said: 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. Click to expand... Sounds like very bad code. Can you post it?
M mmanso Active Member Licensed User Longtime User Aug 13, 2021 #3 Hi Erel, 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. Thanks. Upvote 0
Hi Erel, 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. Thanks.
Erel B4X founder Staff member Licensed User Longtime User Aug 15, 2021 #4 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. Upvote 0
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.
M mmanso Active Member Licensed User Longtime User Aug 16, 2021 #5 So I can't control that "freeze" and cancel whatever it's doing? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Aug 17, 2021 #6 You can but not with broken implementations. Upvote 0