7
7
using System . Diagnostics ;
8
8
using System . IO ;
9
9
using System . Runtime . InteropServices ;
10
+ using System . Threading ;
10
11
using System . Windows ;
11
12
12
13
namespace PointCloudConverter
@@ -25,9 +26,14 @@ public partial class MainWindow : Window
25
26
[ DllImport ( "kernel32.dll" , SetLastError = true ) ]
26
27
static extern bool FreeConsole ( ) ;
27
28
29
+ Thread workerThread ;
30
+ static bool abort = false ;
31
+ public static MainWindow mainWindowStatic ;
32
+
28
33
public MainWindow ( )
29
34
{
30
35
InitializeComponent ( ) ;
36
+ mainWindowStatic = this ;
31
37
Main ( ) ;
32
38
}
33
39
@@ -51,7 +57,11 @@ private void Main()
51
57
var importSettings = ArgParser . Parse ( null , rootFolder ) ;
52
58
53
59
// if have files, process them
54
- if ( importSettings != null ) ProcessAllFiles ( importSettings ) ;
60
+ if ( importSettings != null )
61
+ {
62
+ // NOTE no background thread from commandline
63
+ ProcessAllFiles ( importSettings ) ;
64
+ }
55
65
56
66
// end output
57
67
Console . WriteLine ( "Exit" ) ;
@@ -70,8 +80,11 @@ private void Main()
70
80
}
71
81
72
82
// main processing loop
73
- private static void ProcessAllFiles ( ImportSettings importSettings )
83
+ //private static void ProcessAllFiles(ImportSettings importSettings)
84
+ private static void ProcessAllFiles ( System . Object importSettingsObject )
74
85
{
86
+ var importSettings = ( ImportSettings ) importSettingsObject ;
87
+
75
88
Stopwatch stopwatch = new Stopwatch ( ) ;
76
89
stopwatch . Start ( ) ;
77
90
@@ -84,13 +97,25 @@ private static void ProcessAllFiles(ImportSettings importSettings)
84
97
{
85
98
Console . WriteLine ( "\n Reading file (" + i + "/" + ( len - 1 ) + ") : " + importSettings . inputFiles [ i ] + " (" + Tools . HumanReadableFileSize ( new FileInfo ( importSettings . inputFiles [ i ] ) . Length ) + ")" ) ;
86
99
100
+ //if (abort==true)
101
+
87
102
// do actual point cloud parsing for this file
88
103
ParseFile ( importSettings , i ) ;
89
104
}
90
105
91
106
stopwatch . Stop ( ) ;
92
107
Console . WriteLine ( "Elapsed: " + ( TimeSpan . FromMilliseconds ( stopwatch . ElapsedMilliseconds ) ) . ToString ( @"hh\h\ mm\m\ ss\s\ ms\m\s" ) ) ;
93
108
stopwatch . Reset ( ) ;
109
+
110
+ Application . Current . Dispatcher . Invoke ( new Action ( ( ) =>
111
+ {
112
+ mainWindowStatic . HideProcessingPanel ( ) ;
113
+ } ) ) ;
114
+ }
115
+
116
+ void HideProcessingPanel ( )
117
+ {
118
+ gridProcessingPanel . Visibility = Visibility . Hidden ;
94
119
}
95
120
96
121
// process single file
@@ -218,9 +243,10 @@ private void btnConvert_Click(object sender, RoutedEventArgs e)
218
243
{
219
244
SaveSettings ( ) ;
220
245
StartProcess ( ) ;
246
+ gridProcessingPanel . Visibility = Visibility . Visible ;
221
247
}
222
248
223
- void StartProcess ( bool skipProcess = true )
249
+ void StartProcess ( bool doProcess = true )
224
250
{
225
251
// get args from GUI settings, TODO could directly create new import settings..
226
252
var args = new List < string > ( ) ;
@@ -267,13 +293,27 @@ void StartProcess(bool skipProcess = true)
267
293
Console . WriteLine ( cl ) ;
268
294
269
295
// TODO lock UI, add cancel button, add progress bar
270
- if ( skipProcess == true ) ProcessAllFiles ( importSettings ) ;
296
+ if ( doProcess == true )
297
+ {
298
+ ParameterizedThreadStart start = new ParameterizedThreadStart ( ProcessAllFiles ) ;
299
+ workerThread = new Thread ( start ) ;
300
+ workerThread . IsBackground = true ;
301
+ workerThread . Start ( importSettings ) ;
302
+ }
271
303
}
272
304
}
273
305
306
+
274
307
private void Window_Closing ( object sender , System . ComponentModel . CancelEventArgs e )
275
308
{
276
309
SaveSettings ( ) ;
310
+
311
+ abort = true ;
312
+ if ( workerThread != null )
313
+ {
314
+ workerThread . Abort ( ) ;
315
+ Environment . Exit ( Environment . ExitCode ) ;
316
+ }
277
317
}
278
318
279
319
private void btnBrowseInput_Click ( object sender , RoutedEventArgs e )
@@ -386,5 +426,15 @@ private void btnGetParams_Click(object sender, RoutedEventArgs e)
386
426
private void Window_Loaded ( object sender , RoutedEventArgs e )
387
427
{
388
428
}
429
+
430
+ private void BtnCancel_Click ( object sender , RoutedEventArgs e )
431
+ {
432
+ abort = true ;
433
+ if ( workerThread != null )
434
+ {
435
+ workerThread . Abort ( ) ;
436
+ Environment . Exit ( Environment . ExitCode ) ;
437
+ }
438
+ }
389
439
} // class
390
440
} // namespace
0 commit comments