That code won't compile:
int str = textbox1.text;
is not valid C#: "
" is not a property of the TextBox class, "
" is, and there is no implicit conversion in C# from
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:
if (!int.TryParse(textbox1.text, out val))
... report problem to user, it's not a number ...
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
variables to prevent problems with multiple thread accesses, that 30 * Sleep(100) is only 3 seconds anyway, and that
doesn't close a form - it just removes it from view.