/// <summary> /// Shows the progress dialog while the application is loading data from the TMDb database. /// </summary> /// <param name="currentValue">The current value.</param> /// <param name="maximumValue">The maximum value.</param> /// <param name="easyClientConfigured">An indicator if the TMdbEasy class instance was successfully loaded.</param> public static void ShowProgress(int currentValue, int maximumValue, bool easyClientConfigured) { // create a new instance of the dialog if not already created.. if (progress == null) { progress = new FormTMDBLoadProgress(); if (!Settings.TMDBEnabled || !easyClientConfigured) { // set the image according to the indicator if the TMDb database is in use.. progress.btLoading.ButtonImage = Properties.Resources.sand_class_steel_blue; // refresh the form.. progress.Refresh(); Application.DoEvents(); } // show the progress dialog.. progress.Show(); // set the previous percentage value to invalid.. previousPercentage = -1; } int currentPercentage = 0; // calculate the current percentage value.. if (maximumValue != 0) { currentPercentage = currentValue * 100 / maximumValue; } // only update the current percentage value if it has been changed.. if (currentPercentage != previousPercentage) { // set the percentage text.. progress.lbPercentage.Text = string.Format(formatPercentage, currentPercentage == 0 ? "-" : currentPercentage.ToString()); // refresh the form.. progress.Refresh(); Application.DoEvents(); // save the current progress percentage.. previousPercentage = currentPercentage; } }
/// <summary> /// Close the progress dialog after the application is done loading data from the TMDb database. /// </summary> public static void EndProgress() { // only close the progress form if initialized.. if (progress != null) { // IDisposable so do dispose.. using (progress) { // close the form.. progress.Close(); progress = null; // set the previous percentage value to valid.. previousPercentage = -1; } } }