Window and thread

Although my issue of a thread getting a threadaccessingUI exception when the thread terminated is solvable by keeping the window which created the thread open until the thread has terminated, I’d like to understand better why it happens. The thread is instantiated thus:

importThread = new taskClass () AddHandler, WeakAddressOf importWrapper AddHandler importThread.UIupdater, WeakAddressOf app.UIupdater ()

and importThread is a property of the window. The thread makes use of some properties of the window, and importWrapper is a method of the window.

Is the exception happening because the thread uses some window properties or because it uses a window method?

If I move both the method and the properties away from the window, can I dissociate the window from the thread, such that the window can be closed once the thread is safely running? From the user’s PoV this would be preferable.

Forgot to mention that the code shown above is in the action event handler of a button in the window.

you’re right about the reason
The thread makes use of some properties of the window

Thanks. Now, if I keep those properties and methods outside the window, should that dissociate the window from the thread? I can test it to find out, but setting that up is a fair amount of work.

Usually, you add properties with the same information as the thread needs. Something like

emailAddress = EFEmailAddress.text

when the thread needs the email address from the window.