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


C# Application.Quit方法代码示例

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


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

示例1: With

        // Usage:
        // using Outlook = Microsoft.Office.Interop.Outlook;
        // Action<Outlook.Application> f = o =>
        // {
        //     var mapif = o.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
        // };
        // Outlook1.With(f);
        internal static void With(Action<Outlook.Application> f)
        {
            Outlook.Application app = null;

            try
            {
                app = new Outlook.Application();
                f(app);
            }
            finally
            {
                if (app != null)
                {
                    app.Quit();

                    // Both of the following are needed in some cases,
                    // while none of thme are needed in other cases.
                    Marshal.FinalReleaseComObject(app);
                    GC.Collect();
                }
            }
        }
开发者ID:tatsuya,项目名称:csharp-utility-library,代码行数:29,代码来源:Outlook1.cs

示例2: sendEmail

 private void sendEmail(EmailObject eml, bool errEmail = false)
 {
     string myDate = DateTime.Today.ToString("MMMM dd, yyyy");
     Outlook._Application _app = new Outlook.Application();
     Outlook._NameSpace _ns = _app.GetNamespace("MAPI");
     System.Threading.Thread.Sleep(5000); //wait for app to start
     Outlook.MailItem _mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
     try
     {
         int fileCount = 0;
         if (qryNames != null)
         {
             foreach (var qryName in qryNames)
             {
                 if (System.IO.File.Exists(AttachmentLocation + qryName))
                 {
                     _mail.Attachments.Add(AttachmentLocation + qryName);
                     fileCount++;
                 }
             }
         }
         _mail.Subject = myDate + " " + eml.Subject;
         _mail.To = eml.To;
         _mail.CC = eml.CC;
         _mail.Body = eml.Body;
         _mail.Importance = Outlook.OlImportance.olImportanceNormal;
         System.Threading.Thread.Sleep(5000); //wait for application to catch up with mail object
         ((Outlook.MailItem)_mail).Send();
         _ns.SendAndReceive(true); //send and receive
         _mail.Close(Outlook.OlInspectorClose.olDiscard);
         System.Threading.Thread.Sleep(5000); //wait for application to catch up with mail object
         _app.Quit();
         isSuccessful = true;
     }
     catch (COMException cEx)
     {
         if (cEx.Message != "The item has been moved or deleted.")
         {
             ErrorHandler.Handle(cEx);
             isSuccessful = false;
         }
     }
     catch (Exception x)
     {
         ErrorHandler.Handle(x);
         isSuccessful = false;
     }
 }
开发者ID:MattPaul25,项目名称:SQLSenderForm,代码行数:48,代码来源:GenerateEmail.cs


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