0

I'm trying to update a large project to latest stable Catel version and need to find a ShowDialog alternative, converting to ShowDialogAsync is simply impossible in our use case.

The project stopped integrating Catel updates with Catel V4.2 and there is a large code base with ~960 synchronous (Main Thread) calls to a method using bool? IUIVisualizerService.ShowDialog(IViewModel) most of which process the returned bool? from ShowDialog and perform conditional handling.
So I need to find an alternative that waits for the window to close without blocking the UIThread and it's currently unfeasible to alter all the calling methods to async, use TaskCommands or move the handling of results to EventHandlers due to lack of manpower and company internal management.

This is the old V4.2 code:

var uiVisualizerService = this.GetDependencyResolver().Resolve<IUIVisualizerService>();
return uiVisualizerService.ShowDialog(viewModelToShow);

The ideal scenario is that there is still a Catel service which works like ShowDialog or alternatively find a different way to show DataWindows synchronously.

Edit:
In case it isn't obvious I can't simply use await due to methods in 500+ classes needing to be rewritten and than manually tested(company policy) or use Task.Wait, Task.Result... etc. due to WPF limitation (if I use blocking call on main thread UI freezes up due to intricacies of the WPF causing it to wait for a chance to runSync on the main thread in order to do the actual displaying of the new window(all UI components actually) which causes an inescapable deadlock), so it definitely can't be solved in any of the conventional ways.

Dhidden1
  • 1
  • 2
  • Possible duplicate of [How would I run an async Task method synchronously?](https://stackoverflow.com/questions/5095183/how-would-i-run-an-async-taskt-method-synchronously) – Selvin Apr 02 '19 at 14:50
  • use duplicated question to get `ShowDialogAsync ` results inside extension method of `IUIVisualizerService` called `ShowDialog` ... but better would be to rewrite code to newer Catel version – Selvin Apr 02 '19 at 14:53
  • @Selvin Not really a duplicate to what you linked. I had already tried all the obvious ones and even a version of the asyncHelper (still retried even with the one you linked) but the problem is that I would have to rewrite way too much code to force all calls off of the main thread and without doing that WPF visualization runs into a deadlocks.
    From previous looks at V4.2 of the Catel source I know it just wrapped the old none async method in Task.Run, but it seems to have been dropped and I can't get a public reference to anything like it.
    – Dhidden1 Apr 02 '19 at 16:20
  • So changing to Catel 5.9 with bazillion breaking changes would not be tested and rewriting to async have to be tested?... That's strange.. Seriously, I see two solutions stick with 4.2 or refractor the code – Selvin Apr 02 '19 at 16:51

1 Answers1

0

There are more changes in Catel since 4.2 than just the async stuff that would worry me if I were you. Not sure why you haven't kept it all up-to-date, but you have 2 options:

  1. Stick with 4.2 (would only recommend if product is in maintenance mode)
  2. Bite the bullet and update, you will love the new features and performance upgrades

4.2 was released on September 1, 2015, and 5.9 on January 28, 2019. That's almost 4 years of development and a breaking change release that you need to plan.

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32