@@ -74,6 +74,7 @@ public partial class FormMain : Form
7474 private const string REGEX_COMMAND_LINE_DELAY = @"^-delay=(?<Hours>\d{2}):(?<Minutes>\d{2}):(?<Seconds>\d{2})\.(?<Milliseconds>\d{3})$" ;
7575 private const string REGEX_COMMAND_LINE_LOCK = "^-lock$" ;
7676 private const string REGEX_COMMAND_LINE_JPEG_LEVEL = @"^-jpeglevel=(?<JpegLevel>\d{1,3})$" ;
77+ private const string REGEX_COMMAND_LINE_HIDE_SYSTEM_TRAY_ICON = "^-hideSystemTrayIcon$" ;
7778
7879 /// <summary>
7980 /// Constructor for the main form. Arguments from the command line can be passed to it.
@@ -102,6 +103,17 @@ public FormMain(string[] args)
102103 /// <param name="sender"></param>
103104 /// <param name="e"></param>
104105 private void FormMain_Load ( object sender , EventArgs e )
106+ {
107+ InitializeThreads ( ) ;
108+
109+ DeleteSlides ( ) ;
110+ SearchDates ( ) ;
111+
112+ // Changing the value of this property will automatically call SearchSlides.
113+ toolStripComboBoxImageFormatFilter . SelectedIndex = Properties . Settings . Default . ImageFormatIndex ;
114+ }
115+
116+ private void InitializeThreads ( )
105117 {
106118 runDeleteSlidesThread = new BackgroundWorker
107119 {
@@ -123,12 +135,6 @@ private void FormMain_Load(object sender, EventArgs e)
123135 WorkerSupportsCancellation = true
124136 } ;
125137 runSlideSearchThread . DoWork += new DoWorkEventHandler ( DoWork_runSlideSearchThread ) ;
126-
127- DeleteSlides ( ) ;
128- SearchDates ( ) ;
129-
130- // Changing the value of this property will automatically call SearchSlides.
131- toolStripComboBoxImageFormatFilter . SelectedIndex = Properties . Settings . Default . ImageFormatIndex ;
132138 }
133139
134140 /// <summary>
@@ -420,17 +426,17 @@ private void FormViewer_FormClosing(object sender, FormClosingEventArgs e)
420426 // Close this window.
421427 CloseWindow ( ) ;
422428
423- if ( runDateSearchThread . IsBusy )
429+ if ( runDateSearchThread != null && runDateSearchThread . IsBusy )
424430 {
425431 runDateSearchThread . CancelAsync ( ) ;
426432 }
427433
428- if ( runSlideSearchThread . IsBusy )
434+ if ( runSlideSearchThread != null && runSlideSearchThread . IsBusy )
429435 {
430436 runSlideSearchThread . CancelAsync ( ) ;
431437 }
432438
433- if ( runDeleteSlidesThread . IsBusy )
439+ if ( runDeleteSlidesThread != null && runDeleteSlidesThread . IsBusy )
434440 {
435441 runDeleteSlidesThread . CancelAsync ( ) ;
436442 }
@@ -520,7 +526,7 @@ private void SearchDates()
520526
521527 monthCalendar . BoldedDates = null ;
522528
523- if ( ! runDateSearchThread . IsBusy )
529+ if ( runDateSearchThread != null && ! runDateSearchThread . IsBusy )
524530 {
525531 runDateSearchThread . RunWorkerAsync ( ) ;
526532 }
@@ -531,7 +537,7 @@ private void SearchDates()
531537 /// </summary>
532538 private void DeleteSlides ( )
533539 {
534- if ( ! runDeleteSlidesThread . IsBusy )
540+ if ( runDeleteSlidesThread != null && ! runDeleteSlidesThread . IsBusy )
535541 {
536542 runDeleteSlidesThread . RunWorkerAsync ( ) ;
537543 }
@@ -547,7 +553,7 @@ private void SearchSlides()
547553 ClearPreview ( ) ;
548554 DisableToolStripButtons ( ) ;
549555
550- if ( ! runSlideSearchThread . IsBusy )
556+ if ( runSlideSearchThread != null && ! runSlideSearchThread . IsBusy )
551557 {
552558 runSlideSearchThread . RunWorkerAsync ( ) ;
553559 }
@@ -1110,13 +1116,13 @@ private void StartScreenCapture(string folder, string macro, string format, int
11101116 }
11111117
11121118 // Stop the folder search thread if it's busy.
1113- if ( runDateSearchThread . IsBusy )
1119+ if ( runDateSearchThread != null && runDateSearchThread . IsBusy )
11141120 {
11151121 runDateSearchThread . CancelAsync ( ) ;
11161122 }
11171123
11181124 // Stop the file search thread if it's busy.
1119- if ( runSlideSearchThread . IsBusy )
1125+ if ( runSlideSearchThread != null && runSlideSearchThread . IsBusy )
11201126 {
11211127 runSlideSearchThread . CancelAsync ( ) ;
11221128 }
@@ -1515,17 +1521,17 @@ private void Exit()
15151521 // Close this window.
15161522 CloseWindow ( ) ;
15171523
1518- if ( runDateSearchThread . IsBusy )
1524+ if ( runDateSearchThread != null && runDateSearchThread . IsBusy )
15191525 {
15201526 runDateSearchThread . CancelAsync ( ) ;
15211527 }
15221528
1523- if ( runSlideSearchThread . IsBusy )
1529+ if ( runSlideSearchThread != null && runSlideSearchThread . IsBusy )
15241530 {
15251531 runSlideSearchThread . CancelAsync ( ) ;
15261532 }
15271533
1528- if ( runDeleteSlidesThread . IsBusy )
1534+ if ( runDeleteSlidesThread != null && runDeleteSlidesThread . IsBusy )
15291535 {
15301536 runDeleteSlidesThread . CancelAsync ( ) ;
15311537 }
@@ -1864,6 +1870,7 @@ private void ParseCommandLineArguments(string[] args)
18641870 toolStripMenuItemCloseWindowOnStartCapture . Checked = true ;
18651871 toolStripMenuItemScheduleAtApplicationStartup . Checked = false ;
18661872 toolStripMenuItemShowSlideshowOnStopScreenCapture . Checked = false ;
1873+ toolStripMenuItemShowSystemTrayIcon . Checked = true ;
18671874
18681875 #endregion Default Values for Command Line Arguments/Options
18691876
@@ -1878,6 +1885,7 @@ private void ParseCommandLineArguments(string[] args)
18781885 Regex rgxCommandLineScheduleStopAt = new Regex ( REGEX_COMMAND_LINE_STOPAT ) ;
18791886 Regex rgxCommandLineScheduleStartAt = new Regex ( REGEX_COMMAND_LINE_STARTAT ) ;
18801887 Regex rgxCommandLineJpegLevel = new Regex ( REGEX_COMMAND_LINE_JPEG_LEVEL ) ;
1888+ Regex rgxCommandLineHideSystemTrayIcon = new Regex ( REGEX_COMMAND_LINE_HIDE_SYSTEM_TRAY_ICON ) ;
18811889
18821890 #region Command Line Argument Parsing
18831891
@@ -1985,6 +1993,11 @@ private void ParseCommandLineArguments(string[] args)
19851993 jpegLevel = cmdJpegLevel ;
19861994 }
19871995 }
1996+
1997+ if ( rgxCommandLineHideSystemTrayIcon . IsMatch ( args [ i ] ) )
1998+ {
1999+ toolStripMenuItemShowSystemTrayIcon . Checked = false ;
2000+ }
19882001 }
19892002
19902003 #endregion Command Line Argument Parsing
@@ -1998,6 +2011,8 @@ private void ParseCommandLineArguments(string[] args)
19982011 numericUpDownImageResolutionRatio . Value = ratio ;
19992012 comboBoxScheduleImageFormat . SelectedItem = imageFormat ;
20002013
2014+ InitializeThreads ( ) ;
2015+
20012016 if ( isScheduled )
20022017 {
20032018 toolStripMenuItemScheduleAtApplicationStartup . Checked = true ;
0 commit comments