예제 #1
0
        private void LoadStart(string outputDir, List <LoadListRecord> records)
        {
            try
            {
                // create loader
                loader = new MLoader(outputDir, header.ssmi);
                foreach (LoadListRecord rec in records)
                {
                    loader.AddSource(rec.metaInfo, rec.filePath);
                }

                // create run thread
                Thread thRun = Helper.AsyncRun(delegate
                {
                    try
                    {
                        loader.Load();
                        FormMain.ShowMessage("Load: success!");
                    }
                    catch (Exception ex) { FormMain.ShowMessage(ex.Message); }
                });

                // create monitor thread
                Thread thMonitor = Helper.AsyncRun(delegate
                {
                    MSLoaderStat stat;
                    DateTime startTime = DateTime.Now;
                    while (true)
                    {
                        Thread.Sleep(500);

                        // get loader stat
                        stat = loader.GetStat();

                        // estimate time
                        double realSeondsElapsed = (DateTime.Now - startTime).TotalSeconds;
                        int secondsElapsed       = (int)realSeondsElapsed;
                        int secondsLeft          = (int)(realSeondsElapsed * (stat.tileTotalCnt - stat.tileOutputedCnt) / Math.Max(stat.tileOutputedCnt, 1));
                        int secondsTotal         = Math.Max(1, secondsElapsed + secondsLeft);
                        FormMain.ShowLoaderStatus("Time Elapsed " + Helper.SecondsToString(secondsElapsed)
                                                  + " Time Left " + Helper.SecondsToString(secondsLeft)
                                                  + " Time Total " + Helper.SecondsToString(secondsTotal)
                                                  + "\r\n" + stat.ToString()
                                                  + "\r\nSpeed: " + (int)(stat.tileTotalCnt / secondsTotal) + " tiles/sec");

                        if (!thRun.IsAlive)
                        {
                            return;
                        }
                    }
                });

                // wait for threads to end
                thRun.Join();
                thMonitor.Join();

                // close loader
                loader.Close();
                loader = null;
                FormMain.ShowMessage("Load: close success!");
            }
            catch (Exception ex)
            {
                FormMain.ShowMessage(ex);
            }
        }