I was about to post this a few hours ago, and then my computer crashed, and some business came up that had to be handled, but I'll post it anyway.
I assume that when the OP says "take the amount of seconds from user, and my program will run for this amount of seconds," they mean they want to execute
something (code ? process ? thread ? launch an external application ?), and, if whatever they run is still running after that number of seconds, they want to stop it from running: so it's a time-limit scenario.
I'd guess that
something is in code they have "at hand," and they'll most likely use a thread, or the BackGroundWorker "front-end" to using a thread. Without knowing exactly what the OP is going to run, we can't do anything but fantasize about: how the time-limit is "enforced."
So, that assumption lead me to think the OP wants to convert a string to an integer, which will then used to set the duration of a TimeSpan.
private void someTrigger_Click(object sender, EventArgs e)
{
int seconds;
if (Int32.TryParse(textBox1.Text, out seconds))
{
}
else
{
}
}
But, calculating a "time to quit" in advance of code execution as Canny Stark/Edo suggests here is equally valid, and may well be more efficient depending on factors we can only guess at now.
As you can see, my assumption was that the "something executed" would take in the duration, and handle enforcing the time-limit internally (with or without a callback would, of course, depend on what the OP is doing ... which we don't know).