Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multithread email reader!!!

Multithread email reader!!!

Scheduled Pinned Locked Moved C#
csharpcomalgorithmssecurityhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian_V_V
    wrote on last edited by
    #1

    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
    
    N 1 Reply Last reply
    0
    • C Christian_V_V

      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
      
      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      You don't need two methods Gmail1 and Gmail2. 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 use Invoke/BeginInvoke to avoid cross-thread errors. This[^] ebook should help to get started. :)

      Best wishes, Navaneeth

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups