예제 #1
0
 private void Log(TextBoxBase txtBox, string s)
 {
     if (_ctrl != null)
     {
         Monitor.Enter(_ctrl);
         try
         {
             if (On)
             {
                 _ctrl.BeginInvoke((Action)(() => txtBox.Text += GestLogString(s)));
             }
         }
         finally
         {
             Monitor.Exit(_ctrl);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// アプリケーションのメイン エントリ ポイントです。
        /// </summary>
        /// <param name="parentModule">親モジュール</param>
        public static void Main(IntPtr parentModule)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            System.Resources.ResourceManager rm =
                new System.Resources.ResourceManager("System", typeof(UriFormat).Assembly);
            string dummy = rm.GetString("Arg_EmptyOrNullString");

            ThreadPool.SetMaxThreads(250, 1000);

            MameIF.Initialize(parentModule);
            var threadStart = new ManualResetEvent(false);

            mainThread = new Thread(new ThreadStart(() =>
            {
                threadStart.Set();
                Settings.Default.Reload();

                if (string.IsNullOrWhiteSpace(Settings.Default.OutputDir))
                {
                    Settings.Default.OutputDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                }

                f_CurrentSamplingRate = 48000;
                int.TryParse(Settings.Default.SampleRate, out f_CurrentSamplingRate);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                using (var fs = new FormSplash())
                {
                    fs.Show();
                    if (!IsVSTiMode())
                    {
                        while (fs.Opacity != 1)
                        {
                            fs.Opacity += 0.1;
                            Thread.Sleep(50);
                            fs.Refresh();
                        }
                    }
                    else
                    {
                        formSplash  = fs;
                        fs.Opacity += 1;
                        fs.Refresh();
                    }

                    try
                    {
                        var fm    = new FormMain();
                        fm.Shown += (_, __) =>
                        {
                            if (!IsVSTiMode())
                            {
                                fm.BeginInvoke(new MethodInvoker(() => { fs.Close(); }));
                            }

                            if (!string.IsNullOrEmpty(Settings.Default.EnvironmentSettings))
                            {
                                try
                                {
                                    var dso = StringCompressionUtility.Decompress(Settings.Default.EnvironmentSettings);
                                    InstrumentManager.ClearAllInstruments();
                                    var settings = JsonConvert.DeserializeObject <EnvironmentSettings>(dso, JsonAutoSettings);
                                    InstrumentManager.RestoreSettings(settings);
                                }
                                catch (Exception ex)
                                {
                                    if (ex.GetType() == typeof(Exception))
                                    {
                                        throw;
                                    }
                                    else if (ex.GetType() == typeof(SystemException))
                                    {
                                        throw;
                                    }

                                    MessageBox.Show(ex.ToString());
                                }
                            }
                        };
                        Application.Run(fm);

                        var so = JsonConvert.SerializeObject(SaveEnvironmentSettings(), Formatting.Indented, JsonAutoSettings);
                        Settings.Default.EnvironmentSettings = StringCompressionUtility.Compress(so);
                        Settings.Default.Save();
                    }
                    catch (Exception ex)
                    {
                        if (ex.GetType() == typeof(Exception))
                        {
                            throw;
                        }
                        else if (ex.GetType() == typeof(SystemException))
                        {
                            throw;
                        }

                        MessageBox.Show(ex.ToString());
                    }

                    ShuttingDown?.Invoke(typeof(Program), EventArgs.Empty);
                }
            }))
            {
                Priority = ThreadPriority.BelowNormal
            };
            mainThread.SetApartmentState(ApartmentState.STA);
            mainThread.Start();
            threadStart.WaitOne();
        }
 public override void Write(string message)
 {
     formMain.BeginInvoke(new SimpleStringDelegate(formMain.UpdateStatus), message);
 }
예제 #4
0
 public void AppendLog(string data)
 {
     formMain.BeginInvoke(new MethodInvoker(delegate() { formMain.richTextBoxLog.Text += data + "\n"; }));
     formMain.BeginInvoke(new MethodInvoker(delegate() { formMain.richTextBoxLog.SelectionStart = formMain.richTextBoxLog.Text.Length; }));
     formMain.BeginInvoke(new MethodInvoker(delegate() { formMain.richTextBoxLog.ScrollToCaret(); }));
 }