For a school project we must make a pretty basic game in c#. So far we have created a gameloop and a basic draw function.
Our problem now is that the game randomly stutters. Sometimes it runs perfectly smooth when I run it, other times it stutters pretty bad.

Here is the gameloop:
Code:
while (this.Created)
{
	Application.DoEvents();
	Update();
	Invalidate();
	long currentMS = stopwatch.ElapsedMilliseconds;
	while (stopwatch.ElapsedMilliseconds - currentMS < 16)
	{
		System.Threading.Thread.Sleep(1);
 	}
}
And here is the paint method:
Code:
protected override void OnPaint(PaintEventArgs e)
{
	Graphics g = view.CreateGraphics();
	g.Clear(Color.Black);
	g.FillRectangle(Brushes.White, player.hitbox);
}
Does anyone have any idea what could cause the stutters?