Esempio n. 1
0
        public void Save(ImageAnalyser IA)
        {
            TifFileInfo tifFI = this.tifFI;

            if (tifFI != null)
            {
                if (!tifFI.available)
                {
                    MessageBox.Show("Image is not avaliable!\nTry again later.");
                    return;
                }

                string dir = tifFI.Dir;
                //background worker
                var bgw = new BackgroundWorker();
                bgw.WorkerReportsProgress = true;
                //Add handlers to the backgroundworker
                //Reports when is finished

                bgw.DoWork += new DoWorkEventHandler(delegate(Object o, DoWorkEventArgs a)
                {
                    //check is the directory exist
                    if (dir.IndexOf("\\") > -1)
                    {
                        string checkDir = dir.Substring(0, dir.LastIndexOf("\\"));
                        checkDir        = OSStringConverter.StringToDir(checkDir);
                        if (!System.IO.Directory.Exists(checkDir))
                        {
                            System.IO.Directory.CreateDirectory(checkDir);
                        }
                    }
                    //save file
                    FileEncoder.SaveTif(tifFI, dir, IA);
                    //report progress
                    ((BackgroundWorker)o).ReportProgress(0);
                });

                bgw.ProgressChanged += new ProgressChangedEventHandler(delegate(Object o, ProgressChangedEventArgs a)
                {
                    if (a.ProgressPercentage == 0)
                    {
                        Saved = true;
                        if (tifFI != null)
                        {
                            tifFI.available = true;
                        }
                        IA.FileBrowser.StatusLabel.Text = "Ready";
                    }
                });

                //Start background worker
                tifFI.available = false;
                IA.FileBrowser.StatusLabel.Text = "Saving Tif Image...";

                IA.EnabletrackBars(false);
                bgw.RunWorkerAsync();
                //continue when the sae is done
                while (bgw.IsBusy)
                {
                    Application.DoEvents(); //This call is very important if you want to have a progress bar and want to update it
                                            //from the Progress event of the background worker.
                    Thread.Sleep(10);       //This call waits if the loop continues making sure that the CPU time gets freed before
                                            //re-checking.
                }

                IA.EnabletrackBars(true);
            }
            else if (ResultsExtractor != null)
            {
                //check is the directory exist
                if (dir.IndexOf("\\") > -1)
                {
                    string checkDir = dir.Substring(0, dir.LastIndexOf("\\"));
                    checkDir = OSStringConverter.StringToDir(checkDir);
                    if (!System.IO.Directory.Exists(checkDir))
                    {
                        System.IO.Directory.CreateDirectory(checkDir);
                    }
                }

                var bgw = ResultsExtractor.FileSaver.SaveCTDataFile(
                    (Cell_Tool_3.ResultsExtractor.MyForm)
                    this.ResultsExtractor.myPanel, dir);

                //continue when the sae is done
                while (bgw.IsBusy)
                {
                    Application.DoEvents(); //This call is very important if you want to have a progress bar and want to update it
                                            //from the Progress event of the background worker.
                    Thread.Sleep(10);       //This call waits if the loop continues making sure that the CPU time gets freed before
                                            //re-checking.
                }
            }
        }