add in - Stuck for over 2 months getting an outlook addin to work -


this re-post of previous question, i've spent on 2 months stuck on same issue , haven't made progress of kind. long story short, fires , doesn't. loads once, outlook defaults "inactive" , there's nothing seem able it. when fire, hangs when trying send first email. so, have old appointments outside of date range i'm checking , messagebox appears those. when gets "new" appointments (within date range), pops first messagebox hangs trying send email. first "good" messagebox fails pop up. last advice got regarding issue build log file, couldn't figure out how/what going me or wasn't sure going need log, , gentleman suggested never responded me when asked. thank in advance help, 1 of frustrating things i've ever run in developer.

using system; using system.threading; using system.collections.generic; using system.linq; using system.text; using system.xml.linq; using outlook = microsoft.office.interop.outlook; using office = microsoft.office.core; using microsoft.office.interop.outlook; using system.windows.forms;   namespace outlookaddin1 { public partial class thisaddin {     //outlook.inspectors inspectors;     private void thisaddin_startup(object sender, system.eventargs e)     {         dostuff();     }      private void thisaddin_shutdown(object sender, system.eventargs e)     {     }      #region vsto generated code      /// <summary>     /// required method designer support - not modify     /// contents of method code editor.     /// </summary>     private void internalstartup()     {         this.startup += new system.eventhandler(thisaddin_startup);         this.shutdown += new system.eventhandler(thisaddin_shutdown);     }      //https://msdn.microsoft.com/en-us/library/ms268866.aspx      private void dostuff()     {         outlook.application app = new outlook.application();         thread.sleep(30000); //120 seconds - 120000          datetime firstrun = datetime.now; //so can check every 24 hours? maybe once well.         datetime lastrun = datetime.now;//.addhours(1); //we're going compare firstrun         bool whiletrue = true;         //int test = 0;          try         {             while (whiletrue)             {                 if (whiletrue == true)//(firstrun > lastrun.adddays(1))                 {                     outlook.mapifolder calendarfolder = application.session.getdefaultfolder(outlook.oldefaultfolders.olfoldercalendar);                     outlook.items outlookcalendaritems = calendarfolder.items;                     outlookcalendaritems.includerecurrences = true; //was true                      list<outlook.appointmentitem> lst = new list<outlook.appointmentitem>();                      foreach (outlook.appointmentitem item in outlookcalendaritems)                     {                         lst.add(item);                         //we can handle logic in here without second loop comes next                     }                      foreach (outlook.appointmentitem x in lst)                     {                         datetime startdate = datetime.now.adddays(1);                         datetime enddate = datetime.now.adddays(5);                         datetime apptdate = x.start;                          if (x.subject.tolower().contains("telos"))                         {                             messagebox.show("x: " + x.start + "xyz: " + x.subject);                              if (x.start > startdate && x.start < enddate)                             {                                  microsoft.office.interop.outlook.mailitem email = app.createitem((olitemtype.olmailitem));                                   //outlook.mailitem mail = (outlook.mailitem)globals.thisaddin.application.createitem(outlook.olitemtype.olmailitem);                                 //outlook.recipient recipient = globals.thisaddin.application.session.createrecipient("cindy@soundstewardship.com");                                 //email.sender = recipient.addressentry;                                   //outlook.recipient recipient = app.session.createrecipient("someone@example.com");                                 //email.sender = recipient.addressentry;                                 //email.sentonbehalfofname = "someone@example.com";                                 email.display(true); //was false                                 email.subject = "you have new appointment";                                 email.importance = outlook.olimportance.olimportancelow;                                 email.to = application.session.currentuser.addressentry.address; //current email address.                                 email.body = "this email automatically generated remind have upcoming appointment on: " + x.start.tostring();                                 email.save();                                 email.close(olinspectorclose.olsave);                                 //((outlook._mailitem)email).send();                                 //email.send();                                 //((outlook._mailitem)mailitem).send();                              }                         }                     }                      lastrun = datetime.now;                     whiletrue = false;                 }                 else                 {                     /*                     outlook.mailitem email = new outlook.mailitem();                     email.subject = "this test.";                     email.to = application.session.currentuser.addressentry.address; //current email address.                     email.body = "this test.";                     //email.send();                     ((outlook._mailitem)email).send();                      * */                 }                 }         }         catch (system.exception e) //microsoft.office.interop.outlook.exception e         {             messagebox.show(e.innerexception.tostring());         }                 {             app.quit();         }      }      #endregion } 

}

first of all, there no need create new outlook application instance in code. need use application property of add-in class.

at startup, need read appointments subject contains string

don't use foreach iterating on items in folder. instead, need use find/findnext or restrict methods of items class. may read more these methods in following articles (the sample code included):

how to: retrieve outlook calendar items using find , findnext methods

how to: use restrict method in outlook calendar items

when done i'd recommend using resolve or resolveall methods of recipient(s) class resolve recipients against address book.

also, 75% of time addin loads directly "inactive" , doesn't fire.

microsoft office applications can disable add-ins behave unexpectedly. if application not load add-in, application might have hard disabled or soft disabled add-in.

hard disabling can occur when add-in causes application close unexpectedly. might occur on development computer if stop debugger while startup event handler in add-in executing.

soft disabling can occur when add-in produces error not cause application unexpectedly close. example, application might soft disable add-in if throws unhandled exception while startup event handler executing.when re-enable soft-disabled add-in, application attempts load add-in. if problem caused application soft disable add-in has not been fixed, application soft disable add-in again. read more in how to: re-enable add-in has been disabled article.

also outlook 2013 monitors add-in performance metrics such add-in startup, shutdown, folder switch, item open, , invoke frequency. outlook records elapsed time in milliseconds each performance monitoring metric. example, startup metric measures time required each connected add-in during outlook startup. outlook computes median startup time on 5 successive iterations. if median startup time exceeds 1000 milliseconds (1 second), outlook disables add-in , displays notification user add-in has been disabled. user has option of enabling add-in, in case outlook not disable add-in if add-in exceeds 1000 millisecond performance threshold. see performance criteria keeping add-ins enabled more information.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -