Queuetask Vs. Queuetaskandwait Follow


Hi there,


I am using .NET SDK to print with BarTender.

I observed something interesting when testing TaskQueue.QueueTask() vs. TaskQueue.QueueTaskAndWait().


The essence of printing code looks like the following:


//given a list of labelData as input to print multiple labels with the same template/printer.



//load the template file

1          GetLabelFormatTask task = new GetLabelFormatTask(GetLabelFormatPath(labelFormatName));
2          BtTaskManager.TaskQueue.QueueTaskAndWait(task, 3000);
3          LabelFormat labelFormat = task.LabelFormat;
4          foreach(var labelData: labelDataList) {
5              PrintLabel(labelFormat, labelData);
      public void PrintLabel(LabelFormat labelFormat, IDictionary<string, object> labelData)
6            foreach (var substr in labelFormat.SubStrings.Where(substr => labelData.ContainsKey(substr.Name)))
7                labelFormat.SubStrings.SetSubString(substr.Name, labelData[substr.Name].ToString());
8            PrintLabelFormatTask printTask = new PrintLabelFormatTask(labelFormat);
9            BtTaskManager.TaskQueue.QueueTaskAndWait(task, 3000);
Everything works as expected when QueueTaskAndWait is used for line 9.
However, two things happened when, I switch it to asynchrous queuing with QueueTask in line 9,
9a            BtTaskManager.TaskQueue.QueueTask(task);
1. When in debugging mode, and I steps through the code, first label does NOT come out until stepping into line 9 multiple times, no matter how slow I did it.
2. The number of labels printed and the contents on the labels are unpredictable.
Is this a bug or feature of async queuing?
I also tried to move lines 2-3 before line 5, that is inside the foreach loop to reload the template for every label, then it works as expected.
Thank you for your time.


Domingo Rodriguez
Comment actions Permalink

We've a .NET SDK example (available in C#.Net and VB.Net) which makes use of the QueueTask() asyncronous printing method. Please take a look at its source:

"C:\Program Files (x86)\Seagull\BarTender Suite\SDK\Print Server SDK Samples\TaskMaster\VB"


If this still doesn't help, maybe attach the entire source code of your program for us to examine, the one which works correctly and the one which fails to work. From the code you've attached to this topic, it is not clear to me if you're trying to both make use of QueueTaskAndWait (line 2) and QueueTask (line 9a) in the same code

Please sign in to leave a comment.