@@ -77,34 +77,27 @@ private void PreviewWorker_DoWork(object sender, System.ComponentModel.DoWorkEve
7777 }
7878 catch ( Exception ex )
7979 {
80- e . Result = ex ;
81- previewWorker . CancelAsync ( ) ;
80+ DisplayException ( "Error generating preview" , ex ) ;
8281 }
8382 }
8483 private void PreviewWorker_RunWorkerCompleted ( object sender , RunWorkerCompletedEventArgs e )
8584 {
86- if ( e . Cancelled )
85+ previewButton . Enabled = true ;
86+ ShowNormalCursor ( ) ;
87+ if ( e . Result == null ) { return ; }
88+ var preview = ( Bitmap ) e . Result ;
89+ using ( var previewForm = new Form ( ) )
8790 {
88- DisplayException ( "Error generating preview" , ( Exception ) e . Result ) ;
89- }
90- else
91- {
92- previewButton . Enabled = true ;
93- ShowNormalCursor ( ) ;
94- var preview = ( Bitmap ) e . Result ;
95- using ( var previewForm = new Form ( ) )
91+ previewForm . StartPosition = FormStartPosition . CenterScreen ;
92+ previewForm . Width = preview . Width + 50 ;
93+ previewForm . Height = preview . Height + 50 ;
94+ var pb = new PictureBox
9695 {
97- previewForm . StartPosition = FormStartPosition . CenterScreen ;
98- previewForm . Width = preview . Width + 50 ;
99- previewForm . Height = preview . Height + 50 ;
100- var pb = new PictureBox
101- {
102- Dock = DockStyle . Fill ,
103- Image = preview
104- } ;
105- previewForm . Controls . Add ( pb ) ;
106- previewForm . ShowDialog ( ) ;
107- }
96+ Dock = DockStyle . Fill ,
97+ Image = preview
98+ } ;
99+ previewForm . Controls . Add ( pb ) ;
100+ previewForm . ShowDialog ( ) ;
108101 }
109102 }
110103
@@ -124,21 +117,13 @@ private void PatternWorker_DoWork(object sender, DoWorkEventArgs e)
124117 }
125118 catch ( Exception ex )
126119 {
127- e . Result = ex ;
128- patternWorker . CancelAsync ( ) ;
120+ DisplayException ( "Error generating pattern" , ex ) ;
129121 }
130122 }
131123 private void PatternWorker_RunWorkerCompleted ( object sender , RunWorkerCompletedEventArgs e )
132124 {
133- if ( e . Cancelled )
134- {
135- DisplayException ( "Error generating preview" , ( Exception ) e . Result ) ;
136- }
137- else
138- {
139- crossStitchButton . Enabled = true ;
140- ShowNormalCursor ( ) ;
141- }
125+ crossStitchButton . Enabled = true ;
126+ ShowNormalCursor ( ) ;
142127 }
143128 }
144129}
0 commit comments