943,544 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 1493
  • C# RSS
Apr 7th, 2009
0

Popup Outlook contact makes the WinForm stuck and frozen

Expand Post »
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


C# Syntax (Toggle Plain Text)
  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. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
manfree is offline Offline
3 posts
since Apr 2009
Apr 9th, 2009
0

Re: Popup Outlook contact makes the WinForm stuck and frozen

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.
Team Colleague
Reputation Points: 186
Solved Threads: 147
Cookie... That's it
alc6379 is offline Offline
2,519 posts
since Dec 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Given a subnet mask, how to verify if an IP falls in that subnet.
Next Thread in C# Forum Timeline: WPF in Linux?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC