diff --git a/src/MainForm.cs b/src/MainForm.cs index 3b40f44..c147946 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -1,5 +1,6 @@ using System ; using System.IO ; +using System.Threading ; using System.Drawing ; using System.Collections.Generic ; using System.Windows.Forms ; @@ -46,6 +47,8 @@ public partial class MainForm : Form dataDir, "*.*", SearchOption.AllDirectories ) ; foreach( string fname in files ) { + + // load the next image string extn = Path.GetExtension( fname ).ToLower() ; if ( ! mValidImageExtensions.Contains( extn ) ) continue ; @@ -61,8 +64,20 @@ public partial class MainForm : Form key = fullPath ; } logger.Debug( $"Loading image: {key}" ) ; - mChartImages[ key ] = new ChartImage( key, fullPath ) ; + ChartImage chartImage = new ChartImage( key, fullPath ) ; + mChartImages[ key ] = chartImage ; + + // add the image to the list + ImageListViewItem item = chartImage.imageListViewItem ; + mSearchResults.Invoke( (MethodInvoker) ( () => mSearchResults.Items.Add( item ) ) ) ; } + + // everything has been loaded, allow searches + mSearchQuery.Invoke( (MethodInvoker) ( () => { + mSearchLabel.Enabled = true ; + mSearchQuery.Enabled = true ; + mSearchQuery.Focus() ; + } ) ) ; } private void updateSearchResults( string searchQuery ) diff --git a/src/MainForm.ui.cs b/src/MainForm.ui.cs index 4ccae08..fde4407 100644 --- a/src/MainForm.ui.cs +++ b/src/MainForm.ui.cs @@ -2,6 +2,7 @@ using System ; using System.Text ; using System.Drawing ; using System.IO ; +using System.Threading ; using System.Runtime.InteropServices ; using System.Collections.Generic ; using System.Windows.Forms ; @@ -131,8 +132,11 @@ public partial class MainForm : Form doMainFormResize( null ) ; // load the chart images - loadChartImages() ; - loadSearchResults( mChartImages.Values, "" ) ; + // NOTE: This can take some time, so we update the UI as they are loaded. + mSearchLabel.Enabled = false ; + mSearchQuery.Enabled = false ; + Thread thread = new Thread( () => loadChartImages() ) ; + thread.Start() ; } private void MainForm_FormClosing( object sender, FormClosingEventArgs e )