# Invoking Code Source File

> Invoke a coded source file class within a low-code workflow in Studio to use custom code logic in XAML-based automations.

Use this workflow to invoke a coded source file within a low-code workflow. In this example, we create a class called `TimeSpanHelper` in the `TimeSpanHelper.cs` coded source file. This class generates a random time span based on the specified bounds. To integrate this class in a low-code workflow, we use an **Invoke Workflow File** activity, followed by other low-code activities, depending on the use case.

1. Create a coded source file. For this example, name it `TimeSpanHelper.cs`.
2. In the coded source file, create a public class named **TimeSpanHelper**.
   1. Inside the **TimeSpanHelper** class, declare a private static **Random** object named `_random` to generate random values.
      ```
      private static Random _random = new Random();
      ```
   2. Declare a private static object named `_lockObj` to secure the thread, while working with multiple threads at the same time.
      ```
      private static object _lockObj = new object();
      ```
   3. Implement a public static method called `GetRandomTimeSpanBetween` that takes two integer parameters: `lowerBoundMs` and `upperBoundMs`.
      ```
      public static TimeSpan GetRandomTimeSpanBetween(int lowerBoundMs, int upperBoundMs)
          {
      ```
   4. Use the lock statement with `_lockObj` to secure this thread, while working with multiple threads at the same time.
      ```
      lock (_lockObj)
            {
      ```
   5. Within the lock block, generate a random integer value using `_random.Next` and pass `lowerBoundMs` and `upperBoundMs` as the arguments.
      ```
      var ms = _random.Next(lowerBoundMs, upperBoundMs);
      ```
   6. Convert the generated random value to a `TimeSpan` object using `TimeSpan.FromMilliseconds` and return this value directly from the method with the following command return:
      ```
      return TimeSpan.FromMilliseconds(ms);
      ```

Based on these steps, your final code should look like this:

   ```
     public class TimeSpanHelper
     {
       private static Random _random = new Random();
       private static object _lockObj = new object();

       public static TimeSpan GetRandomTimeSpanBetween(int lowerBoundMs, int upperBoundMs)
       {
         lock (_lockObj)
         {
           var ms = _random.Next(lowerBoundMs, upperBoundMs);
           return TimeSpan.FromMilliseconds(ms);
         }
       }
     }
   ```
3. Create a low-code workflow. For this example, name it `WorkflowUsingCodeSourceFile`.
4. Add a **Log Message** activity to output a random timespan between two and four seconds.
5. In the **Message** field, type the name of the project, call the coded source file, and then call the `GetRandomTimeSpanBetween` method.

In the example below, `CodedWorkflowInteroperability` is the name of the project.

   ```
   CodedWorkflowInteroperability.TimeSpanHelper.GetRandomTimeSpanBetween(2000, 4000)
   ```

## Result

The coded source file is invoked from the low-code workflow. The **Log Message** activity outputs a random time span between the specified bounds.
