This isn't a great fit for the OPs scenario (which I'm guessing they solved 8 years ago), but if you just need to create stopwatches for unit tests or other non-production scenarios then you can use reflection to modify the elapsed time.
This isn't going to give you the best performance, and can break if the underlying implementation of Stopwatch changes, so I'd be very circumspect using this approach.
However, for unit tests where you need to pass around a Stopwatch and can't change to use an alternate implementation, I find this approach to work well and the risk to be acceptable.
/// <summary>
/// Some static mechanisms for creating Stopwatch instances that start from a specific time.
/// </summary>
public static class TestStopwatch
{
/// <summary>
/// Creates a <see cref="Stopwatch"/> instance with a specified amount of time already elapsed
/// </summary>
/// <param name="start">The <see cref="TimeSpan"/> indicated the elapsed time to start from.</param>
public static Stopwatch WithElapsed(TimeSpan start)
{
var sw = new Stopwatch();
var elapsedProperty = typeof(Stopwatch).GetField("_elapsed", BindingFlags.NonPublic | BindingFlags.Instance);
long rawElapsedTicks = start.Ticks;
if (Stopwatch.IsHighResolution)
{
rawElapsedTicks = (long)((double)rawElapsedTicks / (10000000 / (double)Stopwatch.Frequency));
}
elapsedProperty.SetValue(sw, rawElapsedTicks);
return sw;
}
/// <summary>
/// Initializes a new <see cref="Stopwatch"/> instance, sets the elapsed time property to the specified value,
/// and starts measuring elapsed time.
/// </summary>
/// <param name="start">The <see cref="TimeSpan"/> indicated the elapsed time to start from.</param>
public static Stopwatch StartNew(TimeSpan start)
{
var sw = TestStopwatch.WithElapsed(start);
sw.Start();
return sw;
}
}