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.Threadin g.ThreadPool.Qu eueUserWorkItem (new
System.Threadin g.WaitCallback( MoveMail), new object[] { progress,
oItems, destfolder, objConn });
if (oItems.Count == 1)
{
i = -1;
}
else
{
i = 0;
}
progress.ShowDi alog();
}
Loop 2 in MoveMail method :
private void MoveMail(object status)
{
object[] parms = (object[])status;
IProgressCallba ck callback = (IProgressCallb ack)parms[0];
Outlook.Items col = (Outlook.Items) parms[1];
Outlook.MAPIFol der destfolder =
(Outlook.MAPIFo lder)parms[2];
SqlConnection objConn = (SqlConnection) parms[3];
string strInsertQuery = "";
callback.Begin( 0, col.Count);
for (int i = 1; i < col.Count + 1; i++)
{
callback.SetTex t(String.Format ("Performing op: {0}",
i));
callback.StepTo (i);
if (callback.IsAbo rting)
{
return;
}
if (col.Item(i) is Outlook.MailIte m)
{
Outlook.MailIte m oMsg =
(Outlook.MailIt em)col.Item(i);
//subject
if ((oMsg.Subject == null) || (oMsg.Subject == ""))
{
oMsg.Subject = "blank";
}
else
{
//escape quotes in subject
oMsg.Subject = oMsg.Subject.Re place("'", "''");
}
if (oMsg.ReceivedB yName == null)
{
if (oMsg.SenderNam e.IndexOf("'") != -1)
{
string strSenderName =
oMsg.SenderName .Replace("'", "''");
strInsertQuery = "INSERT INTO SeedingResults
(SenderName, ReceivedTime, Subject) VALUES ('" + strSenderName + "','" +
oMsg.ReceivedTi me.ToString() + "','" + oMsg.Subject.To String() + "')";
}
else
{
strInsertQuery = "INSERT INTO SeedingResults
(SenderName, ReceivedTime, Subject) VALUES ('" +
oMsg.SenderName .ToString() + "','" + oMsg.ReceivedTi me.ToString() +
"','" + oMsg.Subject.To String() + "')";
}
}
else
{
if (oMsg.SenderNam e.IndexOf("'") != -1)
{
string strSenderName2 =
oMsg.SenderName .Replace("'", "''");
strInsertQuery = "INSERT INTO SeedingResults
(ReceivedByName , SenderName, ReceivedTime, Subject) VALUES ('" +
oMsg.ReceivedBy Name.ToString() + "','" + strSenderName2 + "','" +
oMsg.ReceivedTi me.ToString() + "','" + oMsg.Subject.To String() + "')";
}
else
{
strInsertQuery = "INSERT INTO SeedingResults
(ReceivedByName , SenderName, ReceivedTime, Subject) VALUES ('" +
oMsg.ReceivedBy Name.ToString() + "','" + oMsg.SenderName .ToString() +
"','" + oMsg.ReceivedTi me.ToString() + "','" + oMsg.Subject.To String() +
"')";
}
}
//write to database
SqlCommand objInsertComman d = new
SqlCommand(strI nsertQuery, objConn);
try
{
objInsertComman d.ExecuteNonQue ry();
}
catch
{
throw new DatabaseExcepti on();
}
oMsg.Move(destf older);
if (callback.IsAbo rting)
{
return;
}
}
}
}
*** Sent via Developersdex http://www.developersdex.com ***