That code won't compile:
int str = textbox1.text;
is not valid C#: "
text
" is not a property of the TextBox class, "
Text
" is, and there is no implicit conversion in C# from
string
to any numeric type.
Additionally, the DoWork delegate is executed on a background worker thread, not the UI thread, so an attempt to access any Control in any way will cause a cross-threading exception - and that includes the TextBox.Text property.
Instead, you need convert the value using Tryparse:
int val;
if (!int.TryParse(textbox1.text, out val))
{
... report problem to user, it's not a number ...
return;
}
...
But that code needs to be executed on the GUI thread, not the background worker.
Handle the TextBox.TextChanged method and update a class-level variable which you can check in your worker thread: but do note that you will need to
lock
variables to prevent problems with multiple thread accesses, that 30 * Sleep(100) is only 3 seconds anyway, and that
Hide
doesn't close a form - it just removes it from view.