Start background thread when a UI button is clicked, and Update UIbutton from background thread

  • Thread starter Thread starter Curious
  • Start date Start date
C

Curious

I was asked these questions during a technical interview:

1) When the user clicks on a button on the form and that invokes a lot
of heavy-duty calculations, what would you do?

My answer:

I would use "BeginInvoke" to start a background worker thread to do
the heavy-duty calculations, in order to avoid blocking the main UI
thread.

Then he asked, "What does 'BeginInvoke' do"? I said it was a .NET
pattern to start a background thread from a UI thread. Did I get it
right?

2) Why can't you simply update a button on the UI thread from a
background thread?

My answer:

If I update a button on the UI thread while the user is clicking on
the button on the UI thread, that would result in memory corruption.
Did I get this one right?
 
Back
Top