how can i send print commands one line at a time with ImmediateNetworkPrinter? #224
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You have to await asynchronous calls in order to make sure they are complete before the next call. The standard in C# is to name methods with the the reason your writes are out of order is that you’re not awaiting the methods properly. All of them are going in at once and they are competing in an indeterminate order. It works with the plain network printer because it internally buffers all writes and flushes them in order for you. please give it a try with async/await and let me know if you still have an issue! |
Beta Was this translation helpful? Give feedback.
-
so i managed to get it working by using System.Collections.Generic.List class to collect the individual byte arrays and then concatenate them into a single array using the System.Linq.Enumerable.SelectMany extension method.
This code creates a List<byte[]> to hold each byte array for each print command, and then uses SelectMany to flatten the list into a single array of bytes. Finally, it passes the flattened byte array to printer.WriteAsync() to send the commands to the printer. |
Beta Was this translation helpful? Give feedback.
You have to await asynchronous calls in order to make sure they are complete before the next call. The standard in C# is to name methods with the
Async
suffix to indicate that they are asynchronous. Your IDE should have given you a warning as well. You can tell a call is Async also because it will return a Task rather than a direct value.the reason your writes are out of order is that you’re not awaiting the methods properly. All of them are going in at once and they are competing in an indeterminate order.
It works with the plain network printer because it internally buffers all writes and flushes them in order for you.
please give it a try with async/await and let me know if you still …