private void button5_Click(object sender, RoutedEventArgs e)
 {
     WindowUniverseOutput.ShowModal(
         new Universe(100, 50),
         new Size(4000, 4000)
         );
 }
Example #2
0
        private void buttonLoadUniverse_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".tssun";
            dlg.Filter     = "TSS Universe (.tssun)|*.tssun";
            bool?dialogRes = dlg.ShowDialog();

            if (dialogRes == true)
            {
                string   filename = dlg.FileName;
                Universe universe = null;
                try
                {
                    universe = SerializeHandler.FromBase64String <Universe>(File.ReadAllText(filename));
                }
                catch
                {
                    MessageBox.Show(LanguageHandler.GetInstance().UniverseFileCorrupted);
                    return;
                }
                if (universe != null)
                {
                    WindowUniverseOutput.ShowModal(
                        universe,
                        new Size(defPixelsWidth, defPixelsHeight)
                        );
                }
            }
        }
Example #3
0
        private void buttonCreatUniverse_Click(object sender, RoutedEventArgs e)
        {
            Tuple <int, int> unSize = WindowUniverseSizeGetter.ShowModal();

            if (unSize != null)
            {
                WindowUniverseOutput.ShowModal(
                    new Universe(unSize.Item1, unSize.Item2),
                    new Size(defPixelsWidth, defPixelsHeight)
                    );
            }
        }
 static void OnOutOfMemory(WindowUniverseOutput window, UniverseOutputManager universeOutputManager)
 {
     try
     {
         universeOutputManager.Dispose();
         GC.Collect();
         window.Dispatcher.Invoke(() =>
         {
             window.Close();
         });
     }
     catch { }
     MessageBox.Show(LanguageHandler.GetInstance().OutOfMemory);
 }
        internal static void ShowModal(Universe universe, Size resolution)
        {
            WindowUniverseOutput  w = new WindowUniverseOutput();
            UniverseOutputManager universeOutputManager = null;

            try
            {
                universeOutputManager = new UniverseOutputManager(universe, w, resolution.Width, resolution.Height);
                //This thread urgently complete the simulation, if taken too much memory.
                //Этот поток экстренно завершит симуляцию, если занято слишком много памяти.
                Thread memoryCheckThread = new Thread(() =>
                {
                    Thread.CurrentThread.Priority = ThreadPriority.Highest;
                    while (true)
                    {
                        int totalMBytesOfMemoryUsed = (int)Process.GetCurrentProcess().WorkingSet64 / 1048576;
                        if (totalMBytesOfMemoryUsed > 900)
                        {
                            OnOutOfMemory(w, universeOutputManager);
                            Thread.CurrentThread.Abort();
                        }
                        Thread.Sleep(300);
                    }
                });
                memoryCheckThread.Start();
                w.ShowDialog();
                memoryCheckThread.Abort();
                universeOutputManager.Dispose();
            }
            catch (OutOfMemoryException ex)
            {
                OnOutOfMemory(w, universeOutputManager);
            }

            GC.Collect();
        }