0

Is there any way I could put this method on a different thread?

I've tried putting the functions inside a Thread, but I cannot use the ref keyword in them. I've also tried making the method asynchronous, but those don't support ref either. It works if I call the function like this:

new Thread(() => x.Animate(0f, 1f, 1000, Ease.Linear)).Start();

but this seems inconvenient.

    public static void Animate(this ref float value, float start, float change, int duration, Ease easing)
    {
        Stopwatch timer = new Stopwatch();
        timer.Start();
        while (timer.ElapsedMilliseconds <= duration)
        {
                value = easing.Execute((int)timer.ElapsedMilliseconds, start, change, duration);
        }
        timer.Stop();
    }
escept
  • 13
  • 4

1 Answers1

-1

If you want to track the variable value, you can make a class level public static property of it instead of a ref parameter.

You should separate that concern into another property or a single instance class.

Ozkan
  • 3,880
  • 9
  • 47
  • 78