I got an WPF form with DataConnectionDialog
(from Microsoft.Data.ConnectionUI
)
And the thing is in case of it called from the same thread as UI it looks like this:
Code is here:
private void btnSetDbConnection_OnClick(object sender, RoutedEventArgs e)
{
string connectionString = null;
try
{
//await Task.Run(() =>
//{
DataConnectionDialog dataConnectionDialog = new DataConnectionDialog(); Microsoft.Data.ConnectionUI.DataSource.AddStandardDataSources(dataConnectionDialog);
dataConnectionDialog.SelectedDataSource = Microsoft.Data.ConnectionUI.DataSource.SqlDataSource;
dataConnectionDialog.SelectedDataProvider = Microsoft.Data.ConnectionUI.DataProvider.SqlDataProvider;
if (DataConnectionDialog.Show(dataConnectionDialog) == System.Windows.Forms.DialogResult.OK)
{
_dataHandler.InitializeConnection(dataConnectionDialog.ConnectionString);
}
//}).ConfigureAwait(false);
}
catch (Exception ex)
{
throw ex;
}
}
And if not - like that:
Code (well, it's the same but uncommented):
private async void btnSetDbConnection_OnClick(object sender, RoutedEventArgs e)
{
string connectionString = null;
try
{
await Task.Run(() =>
{
DataConnectionDialog dataConnectionDialog = new DataConnectionDialog();
Microsoft.Data.ConnectionUI.DataSource.AddStandardDataSources(dataConnectionDialog);
dataConnectionDialog.SelectedDataSource = Microsoft.Data.ConnectionUI.DataSource.SqlDataSource;
dataConnectionDialog.SelectedDataProvider = Microsoft.Data.ConnectionUI.DataProvider.SqlDataProvider;
if (DataConnectionDialog.Show(dataConnectionDialog) == System.Windows.Forms.DialogResult.OK)
{
_dataHandler.InitializeConnection(dataConnectionDialog.ConnectionString);
}
}).ConfigureAwait(false);
}
catch (Exception ex)
{
throw ex;
}
}
Wondering why is so?