How to keep doing codes while the game is in Background?

Hello

i am doing this simple code in c#:

void Start()
{
InvokeRepeating("normalFunction",1,1);
}

void normalFunction()
{
 //Do Something
}

but i noticed that when i alt+tab the invoke code stops invoking.

so how can i keep doing codes even if the game is in background?

also one side question, how can i calculate the time since the players close the game untill he just opened it?

Thank you very much.

You have to enable the Run in background setting.

Edit → Project Settings → Player → Run in background