CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    4

    Resolved [RESOLVED] Popup Outlook contact makes the WinForm stuck and hold

    Hi all

    I would like to popup an Outlook contact via a Click button. The "Popup action" works fine~
    However, after the outlook contact comes up, the WinForm(Form1) seem stuck and hold ....
    I can't move, minimize and maximize the WinForm ?????
    Any body know what is the problem in here ??
    Thanks


    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Outlook = Microsoft.Office.Interop.Outlook;
    
    namespace testing1
    {
        public partial class Form1 : Form
        {
            Outlook.Application oApp = new Outlook.Application();
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
    
            }
            private void FindContactEmailByName(string firstName, string lastName)
            {
                Outlook.NameSpace outlookNameSpace = oApp.GetNamespace("MAPI");
                Outlook.MAPIFolder contactsFolder = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
    
                Outlook.Items contactItems = contactsFolder.Items;
    
                try
                {
                    Outlook.ContactItem contact = (Outlook.ContactItem)contactItems.Find(String.Format("[FirstName]='{0}' and " + "[LastName]='{1}'", firstName, lastName));
                    if (contact != null)
                    {
                        contact.Display(true);
                    }
                    else
                    {
                        MessageBox.Show("The contact information was not found.");
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                FindContactEmailByName("Tom", "Lee");
            }
    
        }
    }
    Attached Files Attached Files
    Last edited by manfree; April 7th, 2009 at 09:41 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Popup Outlook contact makes the WinForm stuck and hold

    Hmmm. This is strange as your code works fine on my machine
    I''m using Vista home and outlook 2003
    There are two things coming in my mind. One is virus checking
    When I start your program since you open Outlook when form1 is created my Avast antivirus just shows up on the screen for a second. Maybe your virus scanner makes troubles ?
    The other thing is that you are not closing outlook and it still sometimes remains in the task manager after closing the program. So I added
    Code:
    privatevoid Form1_FormClosed(object sender, FormClosedEventArgs e) {
       try {
            oApp.Quit();
            oApp = null;
             } catch (Exception ex) {
               MessageBox.Show(ex.Message); 
       }
    }
    This seems to close outlook in the taskmanager too.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Popup Outlook contact makes the WinForm stuck and hold

    One more thing that comes to my mind is that Outlook has this function when ever an external program tries to access outlook, outlook shows a prompt, maybe you are stuck with that.

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: Popup Outlook contact makes the WinForm stuck and hold

    Quote Originally Posted by Shuja Ali View Post
    One more thing that comes to my mind is that Outlook has this function when ever an external program tries to access outlook, outlook shows a prompt, maybe you are stuck with that.
    Yep this was my problem with outlook in XP and was why I never again used it with my programs, but this seems not to be the way when I do his code in a Vista enviroment, maybe because the whole security system has changed ?
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  5. #5
    Join Date
    Apr 2009
    Posts
    4

    Re: Popup Outlook contact makes the WinForm stuck and hold

    Thanks for your help ~~ But i am still using XP platform, not using Vista

    My friend advised me to use >> Threading <<
    then , the parent WinForm won't be stuck anymore ~~ and I tried it and works great ~~ ^_^

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured