Click here to Skip to main content
15,893,401 members
Home / Discussions / C#
   

C#

 
GeneralRe: Got It Pin
jkirkerx4-Sep-20 13:54
professionaljkirkerx4-Sep-20 13:54 
AnswerI have 3 or 5 of them now, yes they need more work Pin
jkirkerx4-Sep-20 14:08
professionaljkirkerx4-Sep-20 14:08 
GeneralRe: I have 3 or 5 of them now, yes they need more work Pin
Gerry Schmitz5-Sep-20 3:58
mveGerry Schmitz5-Sep-20 3:58 
GeneralRe: I have 3 or 5 of them now, yes they need more work Pin
jkirkerx5-Sep-20 7:24
professionaljkirkerx5-Sep-20 7:24 
QuestionCsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
jkirkerx2-Sep-20 13:55
professionaljkirkerx2-Sep-20 13:55 
AnswerRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
OriginalGriff2-Sep-20 22:42
mveOriginalGriff2-Sep-20 22:42 
GeneralRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
jkirkerx3-Sep-20 6:11
professionaljkirkerx3-Sep-20 6:11 
GeneralRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
Dave Kreskowiak3-Sep-20 8:51
mveDave Kreskowiak3-Sep-20 8:51 
AnswerRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas PinPopular
Richard Deeming2-Sep-20 22:50
mveRichard Deeming2-Sep-20 22:50 
GeneralRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
jkirkerx3-Sep-20 6:13
professionaljkirkerx3-Sep-20 6:13 
AnswerRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
Luc Pattyn3-Sep-20 1:36
sitebuilderLuc Pattyn3-Sep-20 1:36 
GeneralRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
jkirkerx3-Sep-20 6:12
professionaljkirkerx3-Sep-20 6:12 
AnswerRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
jkirkerx3-Sep-20 6:31
professionaljkirkerx3-Sep-20 6:31 
AnswerRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
Gerry Schmitz3-Sep-20 10:23
mveGerry Schmitz3-Sep-20 10:23 
QuestionConnect POST server call with HttpListener C# Pin
jdamiancabello2-Sep-20 0:21
jdamiancabello2-Sep-20 0:21 
AnswerRe: Connect POST server call with HttpListener C# Pin
Afzaal Ahmad Zeeshan3-Sep-20 5:19
professionalAfzaal Ahmad Zeeshan3-Sep-20 5:19 
QuestionInheritance problem Pin
Croccodillo19711-Sep-20 5:22
Croccodillo19711-Sep-20 5:22 
AnswerRe: Inheritance problem Pin
Richard Deeming1-Sep-20 7:26
mveRichard Deeming1-Sep-20 7:26 
GeneralRe: Inheritance problem Pin
Croccodillo19711-Sep-20 21:58
Croccodillo19711-Sep-20 21:58 
AnswerRe: Inheritance problem Pin
BillWoodruff9-Sep-20 21:16
professionalBillWoodruff9-Sep-20 21:16 
QuestionHow to reliably exit Outlook using Interop.Outlook? Pin
Server Automator30-Aug-20 14:43
professionalServer Automator30-Aug-20 14:43 
This is the scenario & I was able to make 1/2 of it work: Programmatically launch Outlook 365, send an message & quit Outlook; it must exit. The quitting is the problematic part-- it likes to keep running so I'm thinking I'm not releasing the resources fully forcing it to keep running.

Tons of samples to launch & send a simple message & this is not about that. Outlook 365 has to quit.

This works (simplified for this post though & should be accurate enough): Outlook launches, sends, quits---

using ol = Microsoft.Office.Interop.Outlook;
void Send(string Subject, string EmailBody, string BCC)
{
	ol.Application olOutlook = null;
	ol.MailItem olMsg = null;

	olOutlook = new ol.Application();    //new Outlook app
	olMsg = ( ol.MailItem )olOutlook.CreateItem( ol.OlItemType.olMailItem );
	olMsg.BodyFormat = ol.OlBodyFormat.olFormatHTML;
	olMsg.HTMLBody = EmailBody;
	olMsg.Subject = Subject;
	olMsg.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;
        olMsg.BCC = BCC;
		
         olMsg.Send();
					
	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olMsg );
	olMsg = null;

	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olOutlook.Session );
	olOutlook.Quit();
	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olOutlook.Application );
	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olOutlook );
	olOutlook = null;
	GC.WaitForPendingFinalizers();
	GC.Collect();
	GC.WaitForPendingFinalizers();
	GC.Collect();


Question part 1: Outlook does not quit whenever the EventHandler is subscribed to so the reminders window is suppressed. I'm adding & immediately removing the EventHandler because that's what I've narrowed it down to as the issue for not closing for me. Commenting out the 2 event lines is what's above btw.

using ol = Microsoft.Office.Interop.Outlook;
void Send(string Subject, string EmailBody, string BCC)
{
	ol.Application olOutlook = null;
        
        olOutlook.Reminders.BeforeReminderShow += Reminders_BeforeReminderShow;
        olOutlook.Reminders.BeforeReminderShow -= Reminders_BeforeReminderShow;

	ol.MailItem olMsg = null;

	olOutlook = new ol.Application();    //new Outlook app
	olMsg = ( ol.MailItem )olOutlook.CreateItem( ol.OlItemType.olMailItem );
	olMsg.BodyFormat = ol.OlBodyFormat.olFormatHTML;
	olMsg.HTMLBody = EmailBody;
	olMsg.Subject = Subject;
	olMsg.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;
        olMsg.BCC = BCC;
		
         olMsg.Send();
					
	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olMsg );
	olMsg = null;

	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olOutlook.Session );
	olOutlook.Quit();
	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olOutlook.Application );
	System.Runtime.InteropServices.Marshal.FinalReleaseComObject( olOutlook );
	olOutlook = null;
	GC.WaitForPendingFinalizers();
	GC.Collect();
	GC.WaitForPendingFinalizers();
	GC.Collect();


The EventHandler:
private void Reminders_BeforeReminderShow(ref bool Cancel)
{
    Cancel = true;  //suppresses Outlook reminders from opening
}


Part 2 of this question is where I am right now: Once I add an attachment & send the message, Outlook again does not quit.

What am I missing with releasing these resources? Why is adding & then removing this EventHandler causing issues with quitting Outlook? This is tricky because there are a gazillion "how to send mail" posts but much fewer "how to send mail & quit Outlook" posts.

Also, anything related to killing a task is not being considered because that's a dirty shutdown & will only cause deeper issues with mailboxes etc. over time, so don't post it as a solution.

Thank you

Smile | :)
AnswerRe: How to reliably exit Outlook using Interop.Outlook? Pin
Gerry Schmitz31-Aug-20 4:50
mveGerry Schmitz31-Aug-20 4:50 
AnswerRe: How to reliably exit Outlook using Interop.Outlook? Pin
Dave Kreskowiak31-Aug-20 12:12
mveDave Kreskowiak31-Aug-20 12:12 
AnswerRe: How to reliably exit Outlook using Interop.Outlook? Pin
Mycroft Holmes31-Aug-20 12:15
professionalMycroft Holmes31-Aug-20 12:15 
Questionfind TIMES in string of text Pin
free-pizza30-Aug-20 13:52
free-pizza30-Aug-20 13:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.