private void txtNumOfThreads_KeyPress(object sender, KeyPressEventArgs e)

         private void txtNumOfThreads_KeyPress(object sender, KeyPressEventArgs e)
        {

            if (!char.IsControl(e.KeyChar)
            && !char.IsDigit(e.KeyChar)
            && e.KeyChar != '.')
            {
                e.Handled = true;
            }
        }

Try something like the following

int number

if (int.TryParse(textBox1.Text, out number))
{
    // value is valid whole number.
}
else
{
    // value is not a valid whole number.
}