.NET equivalent of Delphi's Application.ProcessMessages

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?

Thanks

Application.DoEvents

Wait, I see WPF.
It’s only available in Winforms; WPF doesn’t have anything like this.

Insert your processing code into a Dispatcher.BeginInvoke with the right priority: https://docs.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatcher.begininvoke?view=netcore-3.1

OR

Run the database code in a background task: https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task.run?view=netcore-3.1#System_Threading_Tasks_Task_Run_System_Func_System_Threading_Tasks_Task__

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.