本文整理汇总了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();
}
}
}
示例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;
}
}