I have two loops that I am running, one of which is calling a method
which contains the second one. What I want to happen is for when the
second loop exits (the inner loop), then the code will return to the
first loop (the outer loop) and continue executing, but this doesn't
seem to be happening. Here is my code if anybody can help me out :
Loop 1 :
for (int i = 0; i < oItems.Count; i++)
{
oItems = oInbox.Items;
ProgressWindow progress = new ProgressWindow();
progress.Text = "Work";
System.Threading.ThreadPool.QueueUserWorkItem(new
System.Threading.WaitCallback(MoveMail), new object[] { progress,
oItems, destfolder, objConn });
if (oItems.Count == 1)
{
i = -1;
}
else
{
i = 0;
}
progress.ShowDialog();
}
Loop 2 in MoveMail method :
private void MoveMail(object status)
{
object[] parms = (object[])status;
IProgressCallback callback = (IProgressCallback)parms[0];
Outlook.Items col = (Outlook.Items)parms[1];
Outlook.MAPIFolder destfolder =
(Outlook.MAPIFolder)parms[2];
SqlConnection objConn = (SqlConnection)parms[3];
string strInsertQuery = "";
callback.Begin(0, col.Count);
for (int i = 1; i < col.Count + 1; i++)
{
callback.SetText(String.Format("Performing op: {0}",
i));
callback.StepTo(i);
if (callback.IsAborting)
{
return;
}
if (col.Item(i) is Outlook.MailItem)
{
Outlook.MailItem oMsg =
(Outlook.MailItem)col.Item(i);
//subject
if ((oMsg.Subject == null) || (oMsg.Subject == ""))
{
oMsg.Subject = "blank";
}
else
{
//escape quotes in subject
oMsg.Subject = oMsg.Subject.Replace("'", "''");
}
if (oMsg.ReceivedByName == null)
{
if (oMsg.SenderName.IndexOf("'") != -1)
{
string strSenderName =
oMsg.SenderName.Replace("'", "''");
strInsertQuery = "INSERT INTO SeedingResults
(SenderName, ReceivedTime, Subject) VALUES ('" + strSenderName + "','" +
oMsg.ReceivedTime.ToString() + "','" + oMsg.Subject.ToString() + "')";
}
else
{
strInsertQuery = "INSERT INTO SeedingResults
(SenderName, ReceivedTime, Subject) VALUES ('" +
oMsg.SenderName.ToString() + "','" + oMsg.ReceivedTime.ToString() +
"','" + oMsg.Subject.ToString() + "')";
}
}
else
{
if (oMsg.SenderName.IndexOf("'") != -1)
{
string strSenderName2 =
oMsg.SenderName.Replace("'", "''");
strInsertQuery = "INSERT INTO SeedingResults
(ReceivedByName, SenderName, ReceivedTime, Subject) VALUES ('" +
oMsg.ReceivedByName.ToString() + "','" + strSenderName2 + "','" +
oMsg.ReceivedTime.ToString() + "','" + oMsg.Subject.ToString() + "')";
}
else
{
strInsertQuery = "INSERT INTO SeedingResults
(ReceivedByName, SenderName, ReceivedTime, Subject) VALUES ('" +
oMsg.ReceivedByName.ToString() + "','" + oMsg.SenderName.ToString() +
"','" + oMsg.ReceivedTime.ToString() + "','" + oMsg.Subject.ToString() +
"')";
}
}
//write to database
SqlCommand objInsertCommand = new
SqlCommand(strInsertQuery, objConn);
try
{
objInsertCommand.ExecuteNonQuery();
}
catch
{
throw new DatabaseException();
}
oMsg.Move(destfolder);
if (callback.IsAborting)
{
return;
}
}
}
}
*** Sent via Developersdex http://www.developersdex.com ***