Main thread errors during executing a thread unsafe program from a responsive Windows Forms app

48 views Asked by At

I would like to call a thread unsafe program asynchronously to avoid blocking the UI (Windows Forms). But my solution sometimes causes main thread problems "The automation program should be re-worked to make calls in the main thread.".

How can I solve this problem, does anyone have an idea or knows what I do wrong ?

private async Task<int> DoWorkAsync()
{
    await Task.Run(() =>
    {
        var jobFileCreated = JobFileXmlWriter.WriteXmlJobFile(mainFormData);
        // here I start the long running task
        Task <ProcessResult> result = ExecuteShellCommand(argumentXmlPaht,ProcessStartData.Arguments,mainFormData.ExportPath, 500000);
        consoleOutput = result.Result.Output;
    }
});
0

There are 0 answers