locked
Outlook Appointment Problem RRS feed

  • Question

  • Hi,
     
    I have a program that creates an appointment into an outlook calendar. This is done in a thread with theThread.IsBackground = true; and the appointment display set to false, apptItem.Display(false);

    When the thread runs the appointment flicks open and then closes on the screen for each appointment creation(Very annoying). How do I stop this from happening?

    Any advice would be very greatful.

    Here is the snippets

    ThreadStart operation = new ThreadStart(d1.OlJobEntryAppointment);
    Thread theThread = new Thread(operation);
    theThread.Name = d1.Name.ToString();
    theThread.IsBackground =
    true;
    theThread.Start();


    --------
    public void OlJobEntryAppointment()
    {
        Outlook.
    _NameSpace olNS = Globals.ThisAddIn.Application.GetNamespace("MAPI");
        Outlook.
    MAPIFolder olDF = 
            olNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.
    OlDefaultFolders.olFolderCalendar);
        Outlook.
    MAPIFolder olMF = olDF.Folders.GetFirst();

    foreach (Job olaj in Jobs) // olaj = Outlook Appointment Job
    {
        if (olaj != null) {int myHour = 0, myMinute = 0;
        if (olaj.jobDescription.Contains("Bill Prep")) { myHour = 10; }
        else if (olaj.jobDescription.Contains("Move")) { myHour = 13; }
        else { myHour = 10; myMinute = 30; }
        int year = Name.Year;
        int month = Name.Month;
        int day = Name.Day;
        int hour = myHour;
        int minute = myMinute;

        DateTime jobTime = new DateTime(year, month, day, hour, minute, 0);
        TimeSpan duration = new TimeSpan(1, 0, 0, 0);

        Outlook._AppointmentItem apptItem = 
            (Outlook.
    _AppointmentItem)olMF.Items.Add("IPM.Appointment"); 

        apptItem.Display(
    false);
        apptItem.Subject = olaj.jobDescription.ToString();
        apptItem.Start = jobTime;
        if (olaj.jobDescription.Contains("Bill Prep")){ apptItem.End = jobTime.Add(duration); }
        apptItem.Save();
        apptItem.Close(Microsoft.Office.Interop.Outlook.
    OlInspectorClose.olDiscard);
        }
    }
    }

    Monday, November 3, 2008 11:45 PM

Answers

All replies