How to add a timeout to an activity using the UiPath Activity Creator in Visual Studio

I’m trying to create a C# custom activity with timeout propertie using the Activity Creator extension in Visual Studio 2019. The UiPath Add Activities wizard has a toggle for a timeout field, with the default value of 60 seconds, but the code for the timeout does not seem to work to whatever value I fill in the timeout field.

Does anyone have any recommendations?

Hi @Lucas_Clemente,

Did you solved this issue?

Because I had the same issue and instead of using the built-in async function called ExecuteWithTimeout, I initialize a new Task in “ExecuteAsync” instead.

Hi @otico @Lucas_Clemente , did you ever resolve this issue? I am running into this error as well.

Hi @dlockeSB @otico , I alread solved it. I have added all the execution logic inside an “await Task.Run()”. Like this:

await Task.Run(() =>
{
//Add execution logic here
});

//make the returns outside the “await Task.Run()”

I don’t know if it’s correct, but it worked for me. I hope this can help you.

Best regards.

Hi @dlockeSB,

I did as @Lucas_Clemente mentioned here and added a timeout input so I could add a variable timeout from UiPath. See the following code below:


Task task = new Task(() =>
            
// Add you're execution logic here 

);
            task.Start();
            task.Wait(timeout); //This will wait for a time given such as input timeout. timeout is the input from uipath.
            if (!task.IsCompleted)
            {
                //Add exception handling here if the task failed or did not complete
            }

I hope this helps you along the way, just ask if there is anything more.