Multithread email reader!!!
-
Hi Dear all. I`m not a C# programmer , but I manage to make a little email Pop3 reader searching in the internet. This program has a timer and every 5 min looks into an email account and read and download some information. Now what I need is the possibility to read mails from more than one email account at the same time. IE, if I have two Gmail account, the program should look into this two account every 5 min and download the info I need. Please, anyone that help me on this. I´m using Higuchi.net lib for connecting to email accounts, it´s a very good one, anybody can google it and download it, it is free. I have tried multithreading but with no luck. My code is the following:
public partial class Pop3 : Form
{
public Pop3()
{
InitializeComponent();
}private void button1\_Click(object sender, EventArgs e) { if (this.checkBox2.Checked != true && this.checkBox3.Checked != true && this.checkBox1.Checked != true) { MessageBox.Show("Select a Conection Option"); } else { timer1.Tick += new System.EventHandler(this.OnTimerTick); timer1.Enabled = true; timer1.Start(); this.button1.Enabled = false; } } private void OnTimerTick(object sender, EventArgs e) { if (this.checkBox2.Checked == true) Gmail(); if (this.checkBox3.Checked == true) Gmail2(); if (timer1.Interval != 360000) timer1.Interval = 360000; } private void Gmail() { Pop3Client cl = new Pop3Client(); cl.UserName = "xxxxxxxxx@gmail.com"; cl.Password = "xxxxxxxxx"; cl.ServerName = "pop.gmail.com"; cl.Port = 995; cl.AuthenticateMode = Pop3AuthenticateMode.Pop; cl.Ssl = true; cl.Authenticate(); if (cl.Available == true) { if (cl.ReceiveTimeout <= 10000) { if (cl.State == Pop3ConnectionState.Authenticated) { if (Convert.ToInt32(cl.GetTotalMessageCount()) >= 1) { try { int ncount = Convert.ToIn
-
Hi Dear all. I`m not a C# programmer , but I manage to make a little email Pop3 reader searching in the internet. This program has a timer and every 5 min looks into an email account and read and download some information. Now what I need is the possibility to read mails from more than one email account at the same time. IE, if I have two Gmail account, the program should look into this two account every 5 min and download the info I need. Please, anyone that help me on this. I´m using Higuchi.net lib for connecting to email accounts, it´s a very good one, anybody can google it and download it, it is free. I have tried multithreading but with no luck. My code is the following:
public partial class Pop3 : Form
{
public Pop3()
{
InitializeComponent();
}private void button1\_Click(object sender, EventArgs e) { if (this.checkBox2.Checked != true && this.checkBox3.Checked != true && this.checkBox1.Checked != true) { MessageBox.Show("Select a Conection Option"); } else { timer1.Tick += new System.EventHandler(this.OnTimerTick); timer1.Enabled = true; timer1.Start(); this.button1.Enabled = false; } } private void OnTimerTick(object sender, EventArgs e) { if (this.checkBox2.Checked == true) Gmail(); if (this.checkBox3.Checked == true) Gmail2(); if (timer1.Interval != 360000) timer1.Interval = 360000; } private void Gmail() { Pop3Client cl = new Pop3Client(); cl.UserName = "xxxxxxxxx@gmail.com"; cl.Password = "xxxxxxxxx"; cl.ServerName = "pop.gmail.com"; cl.Port = 995; cl.AuthenticateMode = Pop3AuthenticateMode.Pop; cl.Ssl = true; cl.Authenticate(); if (cl.Available == true) { if (cl.ReceiveTimeout <= 10000) { if (cl.State == Pop3ConnectionState.Authenticated) { if (Convert.ToInt32(cl.GetTotalMessageCount()) >= 1) { try { int ncount = Convert.ToIn
You don't need two methods
Gmail1
andGmail2
. Keep only one method and that method should accept the necessary details required for connection. You need to start two threads and execute the method. If you have any shared data that both threads will read/write, you need to use lock. When accessing controls from worker threads you need to useInvoke
/BeginInvoke
to avoid cross-thread errors. This[^] ebook should help to get started. :)Best wishes, Navaneeth