private void MyBtn_Click(object sender, System.EventArgs e) { if (ResultTxt.Text == "Ready for benchmark") { ResultTxt.Text = ""; } Task t = new Task(doSomething); t.Start(); void doSomething() { s.Start(); for (int i = 0; i < int.Parse(numOfTime.Text); i++) { parse.CreateSParseMy(); } s.Stop(); RunOnUiThread(new Action(() => ResultTxt.Text += "My time:" + s.Elasped().ToString() + "\n")); RunOnUiThread(new Action(() => s.Reset())); } }