@@ -53,7 +53,6 @@ namespace SmartImage
5353 // |____/|_| |_| |_|\__,_|_| \__|___|_| |_| |_|\__,_|\__, |\___|
5454 // |___/
5555
56-
5756 public static class Program
5857 {
5958 #region Core fields
@@ -108,12 +107,10 @@ private static async Task Main(string[] args)
108107 var process = Process . GetCurrentProcess ( ) ;
109108 process . PriorityClass = ProcessPriorityClass . AboveNormal ;
110109
111-
112110 /*
113111 * Start
114112 */
115113
116-
117114 /*
118115 * Configuration precedence
119116 *
@@ -132,45 +129,35 @@ private static async Task Main(string[] args)
132129 $ "| PE: { Config . PriorityEngines } " +
133130 $ "| Filtering: { Config . Filtering . ToToggleString ( ) } ";
134131
135- try {
132+ CancellationTokenSource cts = new ( ) ;
136133
137- CancellationTokenSource cts = new ( ) ;
134+ // Run search
138135
139- // Run search
136+ Client . ResultCompleted += OnResultCompleted ;
140137
141- Client . ResultCompleted += OnResultCompleted ;
142- Client . SearchCompleted += ( obj , eventArgs ) =>
143- {
144- OnSearchCompleted ( obj , eventArgs , cts ) ;
138+ Client . SearchCompleted += ( obj , eventArgs ) =>
139+ {
140+ OnSearchCompleted ( obj , eventArgs , cts ) ;
145141
146- if ( Config . Notification ) {
147- AppInterface . ShowToast ( obj , eventArgs ) ;
148- }
149- } ;
150-
151- NConsoleProgress . Queue ( cts ) ;
142+ if ( Config . Notification ) {
143+ AppInterface . ShowToast ( obj , eventArgs ) ;
144+ }
145+ } ;
152146
147+ NConsoleProgress . Queue ( cts ) ;
153148
154- // Show results
155- var searchTask = Client . RunSearchAsync ( ) ;
149+ // Show results
150+ var searchTask = Client . RunSearchAsync ( ) ;
156151
157- // Add original image
158- ResultDialog . Options . Add ( NConsoleFactory . CreateResultOption (
159- Config . Query . GetImageResult ( ) , "(Original image)" ,
160- Elements . ColorMain , - 0.1f ) ) ;
152+ // Add original image
153+ ResultDialog . Options . Add ( NConsoleFactory . CreateResultOption (
154+ Config . Query . GetImageResult ( ) , "(Original image)" ,
155+ Elements . ColorMain , - 0.1f ) ) ;
161156
157+ ResultDialog . Read ( ) ;
162158
163- ResultDialog . Read ( ) ;
159+ await searchTask ;
164160
165- await searchTask ;
166- }
167- catch ( Exception exception ) {
168- #if ! DEBUG
169- // ...
170- #else
171- Console . WriteLine ( exception ) ;
172- #endif
173- }
174161 }
175162
176163 private static bool HandleArguments ( )
@@ -252,18 +239,18 @@ private static bool HandleArguments()
252239 Client . Reload ( ) ;
253240 }
254241 catch ( Exception e ) {
255- Console . WriteLine ( e ) ;
256- Console . ReadLine ( ) ;
242+ Console . WriteLine ( $ "Error: { e . Message } " ) ;
243+ return false ;
257244 }
258245 }
259246
260247 return true ;
261248 }
262249
263-
264250 #region Event handlers
265251
266- private static void OnSearchCompleted ( object ? sender , SearchCompletedEventArgs eventArgs , CancellationTokenSource cts )
252+ private static void OnSearchCompleted ( object ? sender , SearchCompletedEventArgs eventArgs ,
253+ CancellationTokenSource cts )
267254 {
268255 Native . FlashConsoleWindow ( ) ;
269256
0 commit comments