Popup Outlook contact makes the WinForm stuck and frozen

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 3
Reputation: manfree is an unknown quantity at this point 
Solved Threads: 0
manfree's Avatar
manfree manfree is offline Offline
Newbie Poster

Popup Outlook contact makes the WinForm stuck and frozen

 
0
  #1
Apr 7th, 2009
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


  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Outlook = Microsoft.Office.Interop.Outlook;
  10.  
  11. namespace testing1
  12. {
  13. public partial class Form1 : Form
  14. {
  15. Outlook.Application oApp = new Outlook.Application();
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void Form1_Load(object sender, EventArgs e)
  22. {
  23.  
  24. }
  25. private void FindContactEmailByName(string firstName, string lastName)
  26. {
  27. Outlook.NameSpace outlookNameSpace = oApp.GetNamespace("MAPI");
  28. Outlook.MAPIFolder contactsFolder = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
  29.  
  30. Outlook.Items contactItems = contactsFolder.Items;
  31.  
  32. try
  33. {
  34. Outlook.ContactItem contact = (Outlook.ContactItem)contactItems.Find(String.Format("[FirstName]='{0}' and " + "[LastName]='{1}'", firstName, lastName));
  35. if (contact != null)
  36. {
  37. contact.Display(true);
  38. }
  39. else
  40. {
  41. MessageBox.Show("The contact information was not found.");
  42. }
  43. }
  44. catch (Exception ex)
  45. {
  46. throw ex;
  47. }
  48. }
  49.  
  50. private void button1_Click(object sender, EventArgs e)
  51. {
  52. FindContactEmailByName("Tom", "Lee");
  53. }
  54.  
  55. }
  56. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: Popup Outlook contact makes the WinForm stuck and frozen

 
0
  #2
Apr 9th, 2009
You need to run the contact launching code in a new thread, or consider using a background worker to start your FindContactEmailByName method.

Here's a tutorial on the background worker:
http://dotnetperls.com/Content/Backg...roduction.aspx

Basically, when you show a new form like that, the "owner" form that launches the contact.Display(true) call blocks until the contact is closed, or control is returned to the calling form.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC