System.IndexOutOfRangeException when using Eventhandlers on FileBasedProject.RunAutomaticTask

Dear Community, Dear SDL devs,

we recently implemented an application using the Studio 2019 and 2021 API to automatically execute a whole translation process, including pretranslation, analysis and so on. We used the RunAutomaticTask (singular) method http://producthelp.sdl.com/SDK/BatchTaskApi/1.0/html/dcc261d3-0ab5-06dc-5a0f-4293e67022ed.htm as described in the gitlab community examples. Our code resembles the following @ [1]

Unfortunately we get a „System.IndexOutOfRangeException: Der Index war außerhalb des Arraybereichs“, which occurs only when using the taskStatusEventArgsList and messageEventArgsList Eventhandlers like they are used in the SDL Github API examples.

If we run project.RunAutomaticTask with these two parameters, occasionally (round 10-50%) of the tasks pretranslate, analysis, populatetranslationmemories fail due to this exception. If we use the overload of project.RunAutomaticTask without Eventhandlers, the same project runs fine, but we would have no error handling, which would not be feasible for our customers.

Is there advice on using the RunAutomaticTask method without generating this kind of exception?

Best,

Hendrik

[1]

List<TaskStatusEventArgs> taskStatusEventArgsList = new List<TaskStatusEventArgs>();

List<MessageEventArgs> messageEventArgsList = new List<MessageEventArgs>();

 

AutomaticTask ptCreationTask = project.RunAutomaticTask(

targetFiles.GetIds(),

AutomaticTaskTemplateIds.PreTranslateFiles,

(sender, TaskStatus) => { taskStatusEventArgsList.Add(TaskStatus); },

(sender, AnalyzeMessage) => { messageEventArgsList.Add(AnalyzeMessage); }

);

 // error occurs during RunAutomaticTask

CheckEvents (taskStatusEventArgsList, messageEventArgsList);