Skip to content

Commit

Permalink
Fixed an issue with thread-safety
Browse files Browse the repository at this point in the history
  • Loading branch information
mysteryx93 committed Jun 8, 2022
1 parent 75057a6 commit dc4ba83
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## 1.2.3 - 2002-06-07

- Fixed an issue with thread-safety

## 1.2.2 - 2002-06-07

- DialogManager is now thread-safe, dispatching UI calls to the UI thread
Expand Down
4 changes: 2 additions & 2 deletions src/MvvmDialogs.Avalonia/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public DialogManager(IViewLocator? viewLocator = null,
Windows.FirstOrDefault(x => ReferenceEquals(viewModel, x.DataContext)).AsWrapper();

/// <inheritdoc />
protected override void Dispatch(Action action) => _dispatcher.Post(action);
protected override void Dispatch(Action action) => _dispatcher.Post(action, DispatcherPriority.Render);

/// <inheritdoc />
protected override Task<T> DispatchAsync<T>(Func<T> action) => _dispatcher.InvokeAsync(action);
protected override Task<T> DispatchAsync<T>(Func<T> action) => _dispatcher.InvokeAsync(action, DispatcherPriority.Render);
}
4 changes: 2 additions & 2 deletions src/MvvmDialogs.Avalonia/MvvmDialogs.Avalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<AssemblyTitle>MVVM Dialogs for Avalonia</AssemblyTitle>
<Title>MVVM Dialogs for Avalonia</Title>
<AssemblyOriginatorKeyFile>..\..\StrongName.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>1.2.2</AssemblyVersion>
<PackageVersion>1.2.2</PackageVersion>
<AssemblyVersion>1.2.3</AssemblyVersion>
<PackageVersion>1.2.3</PackageVersion>
<Copyright>Copyright © 2009-2022 MVVM Dialogs contributors</Copyright>
<Product>HanumanInstitute.MvvmDialogs</Product>
<PackageId>HanumanInstitute.MvvmDialogs.Avalonia</PackageId>
Expand Down
4 changes: 2 additions & 2 deletions src/MvvmDialogs.Wpf/DialogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public TResult ShowFrameworkDialog<TSettings, TResult>(INotifyPropertyChanged ow
Windows.FirstOrDefault(x => ReferenceEquals(viewModel, x.DataContext)).AsWrapper();

/// <inheritdoc />
protected override void Dispatch(Action action) => _dispatcher.Invoke(action);
protected override void Dispatch(Action action) => _dispatcher.Invoke(action, DispatcherPriority.Render);

/// <inheritdoc />
protected override Task<T> DispatchAsync<T>(Func<T> action) => _dispatcher.InvokeAsync(action).Task;
protected override Task<T> DispatchAsync<T>(Func<T> action) => _dispatcher.InvokeAsync(action, DispatcherPriority.Render).Task;
}
}
4 changes: 2 additions & 2 deletions src/MvvmDialogs.Wpf/MvvmDialogs.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<Title>MVVM Dialogs for WPF</Title>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\StrongName.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>1.2.2</AssemblyVersion>
<PackageVersion>1.2.2</PackageVersion>
<AssemblyVersion>1.2.3</AssemblyVersion>
<PackageVersion>1.2.3</PackageVersion>
<Copyright>Copyright © 2009-2022 MVVM Dialogs contributors</Copyright>
<Product>HanumanInstitute.MvvmDialogs</Product>
<PackageId>HanumanInstitute.MvvmDialogs.Wpf</PackageId>
Expand Down
20 changes: 10 additions & 10 deletions src/MvvmDialogs/DialogManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ protected DialogManagerBase(IViewLocator viewLocator, IFrameworkDialogFactory fr
/// <inheritdoc />
public virtual void Show(INotifyPropertyChanged ownerViewModel, INotifyPropertyChanged viewModel)
{
var view = ViewLocator.Locate(viewModel);
Logger?.LogInformation("View: {View}; ViewModel: {ViewModel}; Owner: {OwnerViewModel}", view?.GetType(), viewModel.GetType(), ownerViewModel.GetType());

Dispatch(() =>
{
var view = ViewLocator.Locate(viewModel);
Logger?.LogInformation("View: {View}; ViewModel: {ViewModel}; Owner: {OwnerViewModel}", view?.GetType(), viewModel.GetType(), ownerViewModel.GetType());

var dialog = CreateDialog(ownerViewModel, viewModel, view);
dialog.Show();
});
Expand All @@ -54,16 +54,16 @@ public virtual void Show(INotifyPropertyChanged ownerViewModel, INotifyPropertyC
/// <inheritdoc />
public virtual async Task ShowDialogAsync(INotifyPropertyChanged ownerViewModel, IModalDialogViewModel viewModel)
{
var view = ViewLocator.Locate(viewModel);
Logger?.LogInformation("View: {View}; ViewModel: {ViewModel}; Owner: {OwnerViewModel}", view?.GetType(), viewModel.GetType(), ownerViewModel.GetType());

await await DispatchAsync(() =>
await await DispatchAsync(async () =>
{
var view = ViewLocator.Locate(viewModel);
Logger?.LogInformation("View: {View}; ViewModel: {ViewModel}; Owner: {OwnerViewModel}", view?.GetType(), viewModel.GetType(), ownerViewModel.GetType());

var dialog = CreateDialog(ownerViewModel, viewModel, view);
return dialog.ShowDialogAsync();
});
await dialog.ShowDialogAsync();

Logger?.LogInformation("View: {View}; Result: {Result}", view?.GetType(), viewModel.DialogResult);
Logger?.LogInformation("View: {View}; Result: {Result}", view?.GetType(), viewModel.DialogResult);
});
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/MvvmDialogs/MvvmDialogs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<Title>MVVM Dialogs</Title>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\StrongName.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>1.2.2</AssemblyVersion>
<PackageVersion>1.2.2</PackageVersion>
<AssemblyVersion>1.2.3</AssemblyVersion>
<PackageVersion>1.2.3</PackageVersion>
<Copyright>Copyright © 2009-2022 MVVM Dialogs contributors</Copyright>
<Product>HanumanInstitute.MvvmDialogs</Product>
<PackageId>HanumanInstitute.MvvmDialogs</PackageId>
Expand Down

0 comments on commit dc4ba83

Please sign in to comment.