|
Hi all,
The following code can popup a particular Outlook contact detail
Click button 1, it opens Tom Lee contact detail
Then, close the Tom Lee contact detail
Click button 2, it opens Sam Green contact detail
It works fine ...
However, if I am going to open both contact detail (without closing the other person contact)
it will come up with an error >>> "A dialog box is open. Close it and try again"
Any body knows how to solve it ?? Thanks
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 System.Threading;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace testing1
{
public partial class Form1 : Form
{
Outlook.Application oApp = new Outlook.Application();
string firstName;
string lastName;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void FindContactEmailByName() {
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)
{
firstName = "Tom";
lastName = "Lee";
popup();
}
private void button2_Click(object sender, EventArgs e)
{
firstName = "Peter";
lastName = "Green";
popup();
}
void popup() {
Thread th = new Thread(FindContactEmailByName);
th.Start();
}
}
}
|
|
|
|
|
How can i create a setup project to my c#.net 3.5 windows application
please give details or some links.
--Thanks
Naren
|
|
|
|
|
try searching it in msdn.microsoft.com.
You can also look at VS2003 or VS2005, it is still the same.
|
|
|
|
|
i had a look into vs2003 and vs2008
but if i want custom installation how can i do that?
means i have a task, sometimes i should install and some times i should not
so while installing how can we ask user wether to install or not?
--Naren
|
|
|
|
|
Use a dialogue box! You would probably need two buttons as a minimum. I would suggest a 'Yes' button and a 'No' button. Oh, and probably the question-mark icon.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
ok, when and where you want me to display that popup box???
|
|
|
|
|
Only you can possible know that!
But, without knowing your circumstances, it would seem reasonable to do it before the setup starts.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
Can any help me in calculating the age in years, months and days using the datetimepicker in C#? I was able to calculate the age in years using the below code:
int ageYears=Datetime.Now.Year-datetimepicker1.Value.Year;
textbox1.text=ageYears.ToString();
Similarly I want to calculate in terms of Months and Days.
Example:
CurrentDate - 07-Apr-2009
DOB - 05-Aug-2008
textbox1 - 0 Years textbox2 - 8 Months textbox3 - 2 Days
Thanks in Advance.
|
|
|
|
|
try this:
DateTime birthDate = new DateTime(1980, 1, 1, 1, 1, 1);
DateTime now = DateTime.Now;
TimeSpan age = now.Subtract(birthDate);
|
|
|
|
|
Not tried it but this[^] could be a starting point.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6 ? Do you hate yourself ? (Christian Graus)
|
|
|
|
|
If you google for 'age calculation c#' you will get several pages of hits. Some are more accurate than others, but they should give you some ideas at least.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
others have given the answer already.
Schdev wrote: int ageYears=Datetime.Now.Year-datetimepicker1.Value.Year;
is plain wrong unless today is December 31.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I have a fairly standard Form1.cs with a listbox to display comms traffic. The comms traffic comes from two different interfaces each of which is handled by it's own background thread. I want to log the traffic in the listbox on Form1 and have set up a delegate / Invoke routine as below in the Form1 class:
public delegate void LogDelegate(string s);
public void log(string message)
{
if (InvokeRequired)
{
Invoke(new LogDelegate(log), new object[] { message });
}
else
{
lb.Items.Add(message);
lb.TopIndex = lb.Items.Count - 1;
}
}
When I try to call log(string) from either of the backgound threads the compiler isn't finding this function and I cant for the life of me see why not. I did try making it a static but that threw lots of errors so I took that away.
What am I doing wrong please?
Many thanks, Bruce
|
|
|
|
|
I suspect this problem has nothing to do with threads.
public void log( string message ) is a normal ( instance ) method in Form1 , so you need to call it using an instance: myForm1.log( message ) .
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Hi Nick, Thanks for your response. The thread will see Form1.log() if I make the log method a static. However if I make it a static the compiler kicks on just about every line of log() with "Object refernece required for ..." I just am not sure what it is looking for that I haven't provided.
Cheers, Bruce
|
|
|
|
|
Assuming Form1 is your main form and you only have one instance of it, put this in Form1 :
static Form1 _Instance = null;
public Form1()
{
if ( _Instance != null ) [ throw an exception or assert or something ]
_Instance = this;
}
public static void LogMessage( string message )
{
_Instance.log( message );
}
Then use this from your threads:
Form1.LogMessage( message );
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Yep, that is why Nick said myForm1.log , not Form1.log.
myForm1 should be a variable pointing to your Form1 instance.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi Bruce,
I think that the problem might be with the:
if (InvokeRequired)<br />
line. Try:
if (this.lb.InvokeRequired)<br />
and then
lb.BeginInvoke(new LogDelegate(log), new object[] { message });<br />
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
The Form and ListBox both run on the same ( UI ) thread, so it doesn't matter which you use.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Yes, of course! How dumb.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks Henry.
That is still throwing compile errors. I am beginning to suspect that the problem is because the two background threads are each in their own class file and that they cannot see the log(message) method in Form1 unless I make that method a static. Having made it a static the compiler is having trouble with pretty much every line of the method as follows:
Error 2 An object reference is required for the non-static field, method, or property 'System.Windows.Forms.Control.Invoke(System.Delegate, params object[])' \\Server1\srvr\Code\PC Programs\SYSTest\SYSTest\Form1.cs 60 17 SYSTest
Can anybody confirm whether I can make the log(message) a static or do I have to restructure my solution to put the background threads inside the Form1 class so I do not have to make the function into a static?
Many thanks for all your valuable input,
Bruce
|
|
|
|
|
The two background threads certainly need to be able to 'see' Form1, the best bet is probably as Nick suggested by passing a reference to Form1 in the constructor of the threads.
The problems caused by making log() static are that log() itself will not be able to see the listbox.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
"The problems caused by making log() static are that log() itself will not be able to see the listbox."
That makes sense. The compiler errors when the method is static could very well be caused by that.
I will try Nick's suggestion and let you know.
Many, many thanks
Bruce
|
|
|
|
|
What is spawning the threads? If it's the same class then you shouldn't be having an issue. If it's a seperate class then the easiest way is to raise an event in that class, that the form can subscribe to, and in the handler invoke the method required.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi Bruce,
the code shown is perfect. However the problem is elsewhere. You have to help those threads to find and use your log method. Especially for logging purposes I tend to do that with static events, like so
(incomplete and unchecked code):
class Form1 : Form {
public Form() {
...
Class2.Logger+=log;
}
public void log(string s) {...}
}
and the "log clients" look like this:
class Class2 {
public static event Action<string> Logger;
private void log(string s) {
if (Logger!=null) Logger(s);
}
}
BTW: the event does not have to be static, but it allows for doing Logger+=log before the actual client objects have been created.
PS: I always like to have a log(Exception) method too; I either solve that by doing the above stuff twice, or by adding the following code in every log client class:
private void log(Exception exc) {
foreach(string s in exc.ToString().Split('\r','\n')) if (s.Length!=0) log(s);
}
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|