Im trying to start a stopwatch from a given time (decimal value pulled from a database). However, because the Stopwatch.Elapsed.Add returns a new timespan rather than modify
I think you want to start your Stopwatch after a certain mount of time specified by a TimeSpan. I wonder why you don't want to start your Stopwatch at a time specified by a DateTime instead?
public class MyStopwatch : Stopwatch
{
public void Start(long afterMiliseconds)
{
Timer t = new Timer() { Interval = 1 };
int i = 0;
t.Tick += (s, e) =>
{
if (i++ == afterMiliseconds)
{
Start();
t.Stop();
}
};
t.Start();
}
}
//use it
var offsetTimeStamp = new System.TimeSpan(0,0,0).Add(TimeSpan.FromSeconds((double)jd.ActualTime));
myStopwatch.Start((long)offsetTimeStamp.TotalMiliseconds);