gameTime is updated by the Game class before
Update() are called, not when it is read, so it will not change between the time your new thread starts and when it stops.
Blocks the UI until the thread exits. This defeats the purpose of using a new thread!
If you just want to be notified when a certain time span has elapsed, and respond to that, @NateBross' answer is correct.
If you really need something running in a separate thread that can't be broken into synchronous steps triggered by
Update(), you might try using a callback:
private void Callback(object sender, EventArgs args)
/// do whatever you wanted when the thread exits...
private event EventHandler ThreadCallback;
protected override void Initialize()
ThreadCallback += Callback;
private bool _startNewTask = false;
private bool _taskIsRunning=false;
private bool _taskCompleted=false;
private void StartTask()
_taskIsRunning = true;
/// sleep for two seconds REGARDLESS of update frequency
if (ThreadCallback != null)
protected override void Update(GameTime gameTime)
Note that I just threw this together in Notepad++. I doubt that it compiles.
When you need to start your new task, set
true. Instead of a delegate, you could shorten things up by just placing the code you want to run at the end of the 2000ms in the Thread() body itself.