@@ -17,19 +17,30 @@ public class WPFEventsHandler : Daisy.SaveAsDAISY.Conversion.Events.IConversionE
1717 {
1818
1919 public ConversionProgress Dialog = null ;
20+ private Dispatcher _dispatcher ;
2021
2122 #region Conversion progress dialog
2223 public void TryInitializeProgress ( string message , int maximum = 1 , int step = 1 )
2324 {
24- if ( Dialog == null ) {
25- Dialog = new ConversionProgress ( ) ;
26- Dialog . Closed += Dialog_Closed ;
27- if ( cancelButtonClicked != null ) {
28- Dialog . setCancelClickListener ( cancelButtonClicked ) ;
25+ Dispatcher . CurrentDispatcher . Invoke ( ( Action ) delegate {
26+ try {
27+ if ( Dialog == null ) {
28+ Dialog = new ConversionProgress ( ) ;
29+ Dialog . Closed += Dialog_Closed ;
30+ if ( cancelButtonClicked != null ) {
31+ Dialog . setCancelClickListener ( cancelButtonClicked ) ;
32+ }
33+ Dialog . Show ( ) ;
34+ _dispatcher = Dispatcher . CurrentDispatcher ;
35+ }
36+ _dispatcher . Invoke ( ( ) => Dialog . InitializeProgress ( message , maximum , step ) ) ;
37+ //Dialog.Dispatcher.Invoke(() => Dialog.InitializeProgress(message, maximum, step));
38+
2939 }
30- Dialog . Show ( ) ;
31- }
32- Dialog . Dispatcher . Invoke ( ( ) => Dialog . InitializeProgress ( message , maximum , step ) ) ;
40+ catch ( Exception e ) {
41+ AddinLogger . Error ( "Unable to show message in progress dialog: " + message ) ;
42+ }
43+ } ) ;
3344 }
3445
3546 private event CancelClickListener cancelButtonClicked = null ;
@@ -49,12 +60,21 @@ private void Dialog_Closed(object sender, EventArgs e)
4960
5061 private void TryShowMessage ( string message , bool isProgress = false )
5162 {
52- if ( Dialog == null ) {
53- Dialog = new ConversionProgress ( ) ;
54- Dialog . Closed += Dialog_Closed ;
55- Dialog . Show ( ) ;
56- }
57- Dialog . Dispatcher . Invoke ( ( ) => Dialog . AddMessage ( message , isProgress ) ) ;
63+ Dispatcher . CurrentDispatcher . Invoke ( ( Action ) delegate {
64+ try {
65+ if ( Dialog == null ) {
66+ Dialog = new ConversionProgress ( ) ;
67+ Dialog . Closed += Dialog_Closed ;
68+ Dialog . Show ( ) ;
69+ _dispatcher = Dispatcher . CurrentDispatcher ;
70+ }
71+ _dispatcher . Invoke ( ( ) => Dialog . AddMessage ( message , isProgress ) ) ;
72+ //Dialog.Dispatcher.Invoke(() => Dialog.AddMessage(message, isProgress));
73+ }
74+ catch ( Exception e ) {
75+ AddinLogger . Error ( "Unable to show message in progress dialog: " + message ) ;
76+ }
77+ } ) ;
5878 }
5979
6080
@@ -223,15 +243,13 @@ public void onPostProcessingSuccess(ConversionParameters conversion)
223243 + conversion . OutputPath ,
224244 true
225245 ) ;
226- TryClosingDialog ( 3000 ) ;
227246 }
228247
229248 #endregion
230249
231250 public void onConversionCanceled ( )
232251 {
233252 TryShowMessage ( "Canceling conversion" ) ;
234- TryClosingDialog ( 3000 ) ;
235253 }
236254
237255 public void onProgressMessageReceived ( object sender , EventArgs e )
@@ -300,11 +318,6 @@ public bool IsContinueDTBookGenerationOnLostElements()
300318 return continueDTBookGenerationResult == MessageBoxResult . Yes ;
301319 }
302320
303- public void OnSuccess ( )
304- {
305- TryClosingDialog ( 3000 ) ;
306- }
307-
308321 public void OnMasterSubValidationError ( string error )
309322 {
310323 MasterSubValidation infoBox = new MasterSubValidation ( error , "Validation" ) ;
0 commit comments