You are accessing the textbox in the thread you have created. You are doing this in your
tw
method. This is not allowed.
You are only getting this error while debugging because illegal cross thread calls are only checked if debugger is attached. Here is the relevant part of code from
MSDN[
^] (Line 300).
[ResourceExposure(ResourceScope.Process)]
private static bool checkForIllegalCrossThreadCalls = Debugger.IsAttached;
You should take a look at
BackgroundWorker
. It may help you achieve what you are trying to do here.