Simple question, though no one at the office seems to know and I can’t find a good way to ask google this. In winforms, if you have a function that handles an event (in this case, on a focusLost), does that function happen on the same thread as the one that fired the event?
So if I have a textbox with focus, which is currently running on the UI thread, and I change focus, will the UI thread then run my function?
Yes, the UI thread will execute UI event handlers.
Generally, in Windows programming, you shouldn’t be touching UI components on other threads. Windows Forms is designed to work via a single thread. If you need to heavy lifting that otherwise may freeze the UI thread, you spawn a new thread to do the work, then push the changes to the UI thread.
You can use SynchronizationContext.Current to post work to the UI thread. BackgroundWorker is handy for this as well.