I came across a situation today. I have a WPF app and one window has two DatePicker controls so the user can edit a date range. Once these dates are changed, some database code occurs in the SelectedDatechanged event. The problem i am running into is that the dropdown calendar of the datepicker doesn’t close until this processing is done. What can i do in .NET to force the UI to update prior to the code in the event proceeding?
Personnally, I will use the second one.
The first one has the default to run the database update code in the UI thread.
The second one does the work in the background, but you need to use Dispatcher.BeginInvoke if you need to update the UI thread.
If your work code is asynchronous, you can use await in your event handler, taking into account that the code before / after the await will run in the UI thread.