当前位置: 首页>>代码示例>>C#>>正文


C# COMObject.Dispose方法代码示例

本文整理汇总了C#中NetOffice.COMObject.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# COMObject.Dispose方法的具体用法?C# COMObject.Dispose怎么用?C# COMObject.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetOffice.COMObject的用法示例。


在下文中一共展示了COMObject.Dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoTest

        public TestResult DoTest()
        {
            Excel.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new NetOffice.ExcelApi.Application();
                application.Visible = true;
                application.DisplayAlerts = false;
                application.Workbooks.Add();
                Excel.Worksheet sheet = application.Workbooks[1].Sheets[1] as Excel.Worksheet;

                Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "ExcelAddinCSharp.TestAddin" select a).FirstOrDefault();
                if(null == addin)
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "COMAddin ExcelAddinCSharp.TestAddin not found.", null, "");

                bool ribbonIsOkay = false;
                bool taskPaneIsOkay = false;
                if (null != addin.Object)
                { 
                    COMObject addinProxy = new COMObject(null, addin.Object);
                    ribbonIsOkay = (bool)Invoker.PropertyGet(addinProxy, "RibbonUIPassed");
                    taskPaneIsOkay = (bool)Invoker.PropertyGet(addinProxy, "TaskPanePassed");
                    addinProxy.Dispose();
                }

                if( ribbonIsOkay && taskPaneIsOkay)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("Ribbon:{0} TaskPane:{1}", ribbonIsOkay, taskPaneIsOkay), null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
开发者ID:vnkolt,项目名称:NetOffice,代码行数:44,代码来源:Test09.cs

示例2: DoTest

        public TestResult DoTest()
        {
            Excel.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new NetOffice.ExcelApi.Application();
                application.Visible = true;
                application.DisplayAlerts = false;
                application.Workbooks.Add();
                Excel.Worksheet sheet = application.Workbooks[1].Sheets[1] as Excel.Worksheet;

                Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.ExcelTestAddinCSharp" select a).FirstOrDefault();
                if (null == addin || null == addin.Object)
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.ExcelTestAddinCSharp or addin.Object not found.", null, "");
                	
                bool addinStatusOkay = false;
                string errorDescription = string.Empty;
                if (null != addin.Object)
                { 
                    COMObject addinProxy = new COMObject(addin.Object);
                    addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay");
                    errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription");
                    addinProxy.Dispose();
                }

                if (addinStatusOkay)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.ExcelTestAddinCSharp Addin Status {0}", errorDescription), null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
开发者ID:netintellect,项目名称:NetOffice,代码行数:44,代码来源:Test09.cs

示例3: DoTest

        public TestResult DoTest()
        {
            Word.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new Word.Application();
                application.Visible = true;
                application.DisplayAlerts = Word.Enums.WdAlertLevel.wdAlertsNone;
                application.Documents.Add();

                Office.COMAddIn addin = (from a in application.COMAddIns where a.ProgId == "NOTestsMain.WordTestAddinCSharp" select a).FirstOrDefault();
                if (null == addin || null == addin.Object)
                    return new TestResult(false, DateTime.Now.Subtract(startTime), "NOTestsMain.WordTestAddinCSharp or addin.Object not found.", null, "");

                bool addinStatusOkay = false;
                string errorDescription = string.Empty;
                if (null != addin.Object)
                {
                    COMObject addinProxy = new COMObject(addin.Object);
                    addinStatusOkay = (bool)Invoker.Default.PropertyGet(addinProxy, "StatusOkay");
                    errorDescription = (string)Invoker.Default.PropertyGet(addinProxy, "StatusDescription");
                    addinProxy.Dispose();
                }

                if (addinStatusOkay)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), string.Format("NOTestsMain.WordTestAddinCSharp Addin Status {0}", errorDescription), null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit(WdSaveOptions.wdDoNotSaveChanges);
                    application.Dispose();
                }
            }
        }
开发者ID:swatt6400,项目名称:NetOffice,代码行数:43,代码来源:Test09.cs

示例4: _excelApplication_SheetActivateEvent

 private void _excelApplication_SheetActivateEvent(COMObject Sh)
 {
     textBoxEvents.BeginInvoke(_updateDelegate, new object[] { "Event SheetActivate called." });
     Sh.Dispose();
 }
开发者ID:swatt6400,项目名称:NetOffice,代码行数:5,代码来源:Example08.cs

示例5: ExcelApplication_SheetDeactivateEvent

 void ExcelApplication_SheetDeactivateEvent(COMObject Sh)
 {
     _sheetDeactivateEvent = true;
     Sh.Dispose();
 }
开发者ID:swatt6400,项目名称:NetOffice,代码行数:5,代码来源:Test06.cs


注:本文中的NetOffice.COMObject.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。