Timespan to execute a particular recording step

Ask general questions here.
Posts: 36
Joined: Mon Jan 16, 2017 3:24 pm

Timespan to execute a particular recording step

Post by manalitatke » Fri Feb 17, 2017 6:15 pm


I am trying to implement a logic in the user code module where i can get the time-span ( difference)between the start of the recording step and the end of the recording step.

I want to introduce this timespan value as a parameter in the 'Delay' Method in the user code.

I tried implementing it by using the StartTime and EndTime calculations and passing their difference as a parameter as follows:

Delay.Duration(Duration.Parse(timedifference), false);

However, i am getting an error saying that: Cannot convert from System.TimeSpan to String.

I want this time difference to be coded as a variable in the C# user code and pass it as a parameter to the Duration method.

The thing is, i want to introduce a delay for my recording step which is dynamic, and is calculated from the timespan required for implementing that recording step instead of waiting for a definite timespan of (10s or 30 s). Sometimes, the definite delay skips a few steps in between and results in a test failure.

I want to implement this logic using the code module instead of data binding using variables.

Is this possible in C# ranorex user code?

Reference questions: http://www.ranorex.com/forum/getting-th ... t4613.html


Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Timespan to execute a particular recording step

Post by krstcs » Fri Feb 17, 2017 6:55 pm

You are trying to parse a string, but passing in a TimeSpan object.

You need to convert the timespan into total milliseconds, as in integer, and then you can pass that into the delay directly.

Code: Select all

Delay.Duration(timedifference.Milliseconds, false);
When you are using methods, you must make sure that you are passing in the correct value type. .NET is strongly-typed.
Shortcuts usually aren't...