3 Replies - 375 Views - Last Post: 17 June 2013 - 12:47 PM Rate Topic: -----

#1 optix212  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 28
  • View blog
  • Posts: 516
  • Joined: 10-October 09

Looping problems...

Posted 17 June 2013 - 09:45 AM

I am having a difficult time trying to figure out what is wrong with my for loop..

I have a program set up to populate a listview with an emails Sender and the subject. I am doing this through IMAP. Now, the listview populates just fine.. But the problem I am having is opening the actual body of the email. I have set it up to when the listview item is double clicked, it will do a for loop through entire list of emails and check the subject and sender of each email against the items email and sender. The problem is that when i double click the item in the tree, it just gives me the first email in the list.

Here is my code:
                    try
                    {
                        oClient.Connect(oServer);
                        MailInfo[] infos = oClient.GetMailInfos();
                        for (int i = 0; i < infos.Length; i++)
                        {
                           // MessageBox.Show("Looping");
                            MailInfo info = infos[i];
                            Mail oMail = oClient.GetMail(info);
                            if (hit.Item.Text == oMail.From.ToString() && hit.Item.SubItems[0].Text == oMail.Subject.ToString());
                            {
                                ReadMail myReadMail = new ReadMail();
                                myReadMail.Show();
                                myReadMail.AddToFromBox(oMail.TextBody.ToString(), oMail.From.ToString(), oMail.Subject.ToString());
                                return;
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        MessageBox.Show(exc.Message);
                    }



sorry if my explanation of the problem isn't clear enough.. I don't know how else to explain it.

Is This A Good Question/Topic? 0
  • +

Replies To: Looping problems...

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Looping problems...

Posted 17 June 2013 - 10:01 AM

Have you tried using breakpoints to check what is happening at each stage of the loop.
Was This Post Helpful? 1
  • +
  • -

#3 optix212  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 28
  • View blog
  • Posts: 516
  • Joined: 10-October 09

Re: Looping problems...

Posted 17 June 2013 - 10:23 AM

Yeah, I figured it out. I had a stupid semicolon at the end of the for loop declaration. It is now showing the appropriate email. It just takes a hell of a long time because I have to use this for loop.. Idk how else to do it though.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3652
  • View blog
  • Posts: 11,421
  • Joined: 05-May 12

Re: Looping problems...

Posted 17 June 2013 - 12:47 PM

That is because of the way IMAP works. Unless you write extra code to cache data locally, you'll keep on hitting the network to get data.

Consider building a caching proxy around your IMAP API.

As an aside, the 'oFoo' Hungarian naming convention that you are using is against the .NET recommendations for naming conventions.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1