/// <summary> /// Start loading proces /// </summary> private void load(object sender, MouseButtonEventArgs e) { GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true); correctcats = false; Error(false); string filePath; duplicated = 0; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "txt files (*.txt)|*.txt*|ast files (*.ast)|*.ast*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; bool repeted = false; bool CorrectParameters = true; if (openFileDialog.ShowDialog() == true && openFileDialog.SafeFileName != null) //Check if selected file is valid { foreach (string name in Archivo.names) //Check if selected file is already loaded { if (name == openFileDialog.FileName) { repeted = true; } } if (repeted == true) { RepedetFileDialog file = new RepedetFileDialog(); //If selected file is already loaded ask if we want to load it again file.GetLoadform(this); file.ShowDialog(); } if (duplicated == 0) { if (Archivo.names.Count > 0) //If we have already any file loaded ask days to order files correctly { CorrectParameters = false; SelectDay day = new SelectDay(); day.GetForm(this); day.ShowDialog(); if (seconds != -950400) { CorrectParameters = true; } } //Ask which categories to load Selectcat selcat = new Selectcat(); selcat.GetLoadForm(this); selcat.ShowDialog(); if (CorrectParameters == true && correctcats == true) { Form.LoadDisableButtons(); //Disable all buttons Startloading(); //set this page to loading page new Thread(() => //load in a new thread so we can still do other things while loading { Thread.CurrentThread.IsBackground = true; filePath = openFileDialog.FileName; this.result = Archivo.Leer(filePath, seconds, SelectedCats); //Load file in readfiles class if (result == 1) //if result 1 means everything went ok { this.Dispatcher.Invoke(() => //change this page controls { Form.Getfichero(Archivo); //sent load file to main window this.Stoploading(); //stop loading this.Load_load(sender, e); //put this page in normal mode, not loading mode Form.LoadActiveButtons(); //Active all buttons }); } else //anything went wrong { this.Dispatcher.Invoke(() => { this.Load_load(sender, e); //put this page in normal mode, not loading mode this.Stoploading(); //stop loading Form.LoadActiveButtons(); //Active buttons Error(true); //show somwthing went wrong }); } }).Start(); //start thread } } } }