Please format your code making your code easier for others to read. I have done that for you.
What different behaviors are you seeing?
There could be race conditions with the signal’s value when calling the task and when the timeout expires.
Are you sure there are no other differences in tool switches like timescale directives when running in the different modes?