login about faq

Hello,

I have an object of Imap class. I am trying to call the same (or not) methods of my Imap object in the same time in two different threads. Will all this methods return correct data when they complete?

For a example:

I want to get emails from mailbox:

public class ImapWrapper { private Imap _imap = new Imap();

// some methods for initializing Imap connection here

public Email[] GetMailboxMessages(string mailbox, int[] uids)

{
if (!_imap.SelectMailbox(mailbox)) return null;

List<email> messages = new List<email>();

foreach (int uid in uids) {

 Email email = _imap.FetchSingle(uid, true);

 if (email != null)
    messages.Add(email);

}

return messages.ToArray(); } }

In the main program I create an instance of ImapWrapper class:

... ImapWrapper wr = new ImapWrapper();

start in one thread wr.GetMessages("Inbox", new int[] {1, 2, 3})

start in another thread wr.GetMessages("UserFolder", new int[] {5, 6, 7})

Will results of two calls be correct?

asked Feb 19 '14 at 08:10

kuligintim's gravatar image

kuligintim
316911

edited Feb 24 '14 at 01:25


For virtually any Internet protocol based on commands and responses, it would make no sense for multiple threads to be trying to send commands and receive responses on the same connection at the same time. Everything would be a mess -- commands and responses would be intermixed and it just doesn't make sense.

(This is not necessarily the case w/ SSH because of the concept of logical channels within a single connection. But for SMTP, HTTP, IMAP, POP3, FTP, etc. this fundamental restriction applies.)

link

answered Feb 24 '14 at 17:02

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×174

Asked: Feb 19 '14 at 08:10

Seen: 635 times

Last updated: Feb 24 '14 at 17:02

powered by OSQA