Example #1
0
        public void OpenWinFormInSeparateThread(IRibbonControl control)
        {
            if (!CheckWorkbook())
            {
                return;
            }

            if (_refEditForm2 == null)
            {
                Thread thread = new Thread(() =>
                {
                    try
                    {
                        _refEditForm2         = new RefEditForm(_excelThreadId);
                        _refEditForm2.Closed += delegate { _refEditForm2 = null; };
                        _refEditForm2.ShowDialog();
                    }
                    catch (Exception e)
                    {
                        Debug.Print("Error: {0}", e);
                    }
                });

                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            }
            else
            {
                _refEditForm2.Invoke(new Action(() => _refEditForm2.Activate()));
            }
        }
Example #2
0
        public void OpenWinFormInExcelThread(IRibbonControl control)
        {
            if (!CheckWorkbook())
            {
                return;
            }

            if (_refEditForm1 == null)
            {
                try
                {
                    _refEditForm1         = new RefEditForm(_excelThreadId);
                    _refEditForm1.Closed += delegate { _refEditForm1 = null; };
                    _refEditForm1.Show();
                }
                catch (Exception e)
                {
                    Debug.Print("Error: {0}", e);
                }
            }
            else
            {
                _refEditForm1.Activate();
            }
        }