Hi!

I have some strange problems when I'm working with several GW mailboxes from
different threads. Everything seems to be ok when things are simgle
threaded, but when I go to multiple threads my program bails out in
different places. Mostly on FindMessages, more rarely on MultiLogin. Here is
a sample: I create two threads. Each infinitely does the following things:
logs on, finds read messages, do something with them (e.g. read their
subjects) and releases objects. This can work for some minutes, but
occasionally FindMessages (or something else) bails out with some strange
messages (such as "Field expected").

I'm using MSVS and standard Interop. Any ideas?

__________________________________________________ _______________

using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using GroupwareTypeLibrary;

namespace GWTest
{
class MsgReader
{
private readonly string UserName;
private readonly string Password;
private readonly string Host;

MsgReader(string login, string password, string server)
{
UserName = login;
Password = password;
Host = server;
}

void Start()
{
StringBuilder sb = new StringBuilder();
while (true)
{
DIGWSession2 session = null;
DIGWAccount account = null;
DIGWFolder mailbox = null;
MessageList msglist = null;

try
{
session = new GWSession2();
account = session.MultiLogin(UserName, "/ntservice
/ipa-" + Host + " /ipp-1677", Password, 1, 0);
mailbox = account.MailBox;
msglist = mailbox.FindMessages("(READ)");

foreach (DIGWMessage message in msglist)
{
DIGWFormattedText ft = message.Subject;
sb.Append(ft.PlainText + "\n");
Marshal.ReleaseComObject(ft);
Marshal.ReleaseComObject(message);
}
}
finally
{
Marshal.ReleaseComObject(msglist);
Marshal.ReleaseComObject(mailbox);
Marshal.ReleaseComObject(account);
Marshal.ReleaseComObject(session);
}
}
}

static void Main()
{
MsgReader john = new MsgReader("John", "q", "vj-srv");
MsgReader peter = new MsgReader("Peter", "q", "vj-srv");

Thread johnth = new Thread(john.Start);
Thread peterth = new Thread(peter.Start);

johnth.Start();
peterth.Start();

johnth.Join();
peterth.Join();
}
}
}