Hello
As I debug the C# code with a break point and by pressing F11 I
eventually get a message stating:
ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x17aeb8 to
COM context 0x17abd8 for 60 seconds. The thread that owns the destination
context/apartment is most likely either doing a non pumping wait or
processing a very long running operation without pumping Windows messages.
This situation generally has a negative performance impact and may even lead
to the application becoming non responsive or memory usage accumulating
continually over time. To avoid this problem, all single threaded apartment
(STA) threads should use pumping wait primitives (such as
CoWaitForMultipleHandles) and routinely pump messages during long running
operations.
then eventually I get the index out of range message.
If I take out the break point and I dont press F11 to debug and just select
Debug - Start Debugging then I just get the message:
Index was out of range. Must be non-negative and less than size of the
collection. Parameter name:index.
What do you handle these types of errors? The error does not happen in the
first half of the program where the list is created it happens in the second
half on the second on line 236 (however it is actually one dll call by a
form). I have pointed the first half and the second half of the program and
I have pointed out where line 236 is in the second half in the code so you
know what line in the code it is bombing on:
//****this is the first half of the program which has no problem
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Threading;
namespace NotUsedProj
{
class NotUsedList
{
private int ADDist;
private int EDDist;
public NotUsedList(int ADD, int EDD)
{
ADD = ADDist;
EDD = EDDist;
}
public int ADD
{
get { return ADDist; }
set { ADDist = value; }
}
public int EDD
{
get { return EDDist; }
set { EDDist = value; }
}
public static List<objectNotUsedDLList()
{
List<objectdtList = new List<object>();
List<objectNotUsedTbl = new List<object>();
List<objectRetNotUsed = new List<object>();
dtList = NotUsedData.GetDLData();
int AEsubtotal = 0;
string AEspace = " ";
int HoldAD = Convert.ToInt32(dtList[0]);
int HoldED = Convert.ToInt32(dtList[1]);
int CurrAD = 0;
int CurrED = 0;
//int NotUsed = dtList.Count /2;
int FromED = 0;
string ToEd = " ";
string nuRange = " ";
string isRange = " ";
int grandTotalED = 0;
int noFirst = 0;
//NotUsedTbl.Clear();
//MessageBox.Show("total recs in dtlist is " + dtList.Count);
for (int i = 2; i <dtList.Count; i++)
{
CurrAD = Convert.ToInt32(dtList[i]);
i++;
CurrED = Convert.ToInt32(dtList[i]);
if ((HoldAD == CurrAD) & (CurrED == (HoldED + 1)))
{
AEsubtotal++;
if ((noFirst == 0) & (isRange == "N") & (ToEd == " "))
{
AEsubtotal = AEsubtotal + 1;
grandTotalED = grandTotalED + 2;
noFirst = 1;
}
else
grandTotalED++;
NotUsedTbl.Add(HoldAD.ToString());
if (isRange == "N" | isRange == " ")
{
FromED = HoldED;
ToEd = CurrED.ToString();
}
if (isRange == "Y")
{
ToEd = CurrED.ToString();
}
nuRange = FromED.ToString() + " To " + ToEd;
NotUsedTbl.Add(nuRange );
NotUsedTbl.Add(AEsubtotal);
NotUsedTbl.Add(grandTotalED);
isRange = "Y";
HoldAD = CurrAD;
HoldED = CurrED;
}
if ((HoldAD == CurrAD) & (CurrED (HoldED + 1)))
{
AEsubtotal++;
grandTotalED++;
if (isRange == "N")
{
NotUsedTbl.Add(CurrAD.ToString());
FromED = CurrED;
nuRange = FromED.ToString();
NotUsedTbl.Add(nuRange);
}
else
{
NotUsedTbl.Add(HoldAD.ToString());
FromED = HoldED;
nuRange = FromED.ToString();
NotUsedTbl.Add(nuRange);
}
NotUsedTbl.Add(AEsubtotal);
NotUsedTbl.Add(grandTotalED);
isRange = "N";
HoldAD = CurrAD;
HoldED = CurrED;
}
if ((HoldAD < CurrAD))
{
AEsubtotal = 0;
AEsubtotal++;
grandTotalED++;
if (isRange == "Y" | isRange == "N")
{
NotUsedTbl.Add(CurrAD.ToString());
FromED = CurrED;
nuRange = FromED.ToString();
NotUsedTbl.Add(nuRange);
}
else
{
NotUsedTbl.Add(HoldAD.ToString());
FromED = HoldED;
nuRange = FromED.ToString();
NotUsedTbl.Add(nuRange);
}
NotUsedTbl.Add(AEsubtotal);
NotUsedTbl.Add(grandTotalED);
HoldAD = CurrAD;
HoldED = CurrED;
isRange = "N";
}
ToEd = " ";
}
//MessageBox.Show(" total recs = " + NotUsedTbl.Count);
//return NotUsedTbl;
//*** this is the second half of the program and wher the problem is
string contED;
string retED;
int ADhold = 0;
string EDhold = " ";
int ADcurr = 0;
string EDcurr = " ";
int svAD = 0;
string svEd = " ";
int ctSwitch = 0;
int tempSub = 0;
int tempGrand = 0;
int svSub = 0;
int svGrand = 0;
int subHold = 0;
int grandHold = 0;
int z = 0;
ADhold = Convert.ToInt32(NotUsedTbl[z]); // this is the ad
z++;
EDhold = Convert.ToString(NotUsedTbl[z]);// this is the ed
retED = Convert.ToString(EDhold);
z++;
svSub = Convert.ToInt32(NotUsedTbl[z]); // this is the subtotal
z++;
svGrand = Convert.ToInt32(NotUsedTbl[z]); //this is the grandtotal
z++;
ADcurr = Convert.ToInt32(NotUsedTbl[z]); // another ad
z++;
EDcurr = Convert.ToString(NotUsedTbl[z]); // another ed
contED = Convert.ToString(EDcurr);
z++;
tempSub = Convert.ToInt32(NotUsedTbl[z]);
z++;
tempGrand = Convert.ToInt32(NotUsedTbl[z]);
for (int i = 7; i < NotUsedTbl.Count; i++)
{
if (ADhold == ADcurr)
{
while (ADhold == ADcurr)
{
if (retED.Length 2)
retED = retED.Substring(0,3);
bool findED = contED.StartsWith(retED);
if (findED)
{
ADhold = ADcurr;
EDhold = EDcurr;
z++;
ADcurr = Convert.ToInt32(NotUsedTbl[z]);
retED = EDhold.ToString();
z++;
EDcurr = Convert.ToString(NotUsedTbl[z]);
contED = EDcurr.ToString();
z++;
svSub = Convert.ToInt32(NotUsedTbl[z]);
z++;
svGrand = Convert.ToInt32(NotUsedTbl[z]);
//MessageBox.Show("found at " + retED.Index);
}
else
{
RetNotUsed.Add(ADhold);
RetNotUsed.Add(EDhold);
if (ctSwitch == 0)
{
subHold = tempSub;
grandHold = tempGrand;
ctSwitch = 1;
}
else
{
subHold = svSub;
grandHold = svGrand;
ctSwitch = 1;
}
RetNotUsed.Add(subHold);
RetNotUsed.Add(grandHold);
ADhold = ADcurr;
EDhold = EDcurr;
retED = EDhold.ToString();
z++;
//***
//*** line 236 ADcurr =
Convert.ToInt32(NotUsedTbl[z]);
//***
z++;
EDcurr = Convert.ToString(NotUsedTbl[z]);
contED = EDcurr.ToString();
z++;
svSub = Convert.ToInt32(NotUsedTbl[z]);
z++;
svGrand = Convert.ToInt32(NotUsedTbl[z]);
}
}
}
else if (ADhold < ADcurr)
{
RetNotUsed.Add(ADhold);
RetNotUsed.Add(EDhold);
if (ctSwitch == 0)
{
subHold = tempSub;
grandHold = tempGrand;
ctSwitch = 1;
}
else
{
subHold = svSub;
grandHold = svGrand;
ctSwitch = 1;
}
RetNotUsed.Add(subHold);
RetNotUsed.Add(grandHold);
ADhold = ADcurr;
EDhold = EDcurr;
retED = EDhold.ToString();
z++;
ADcurr = Convert.ToInt32(NotUsedTbl[z]);
z++;
EDcurr = Convert.ToString(NotUsedTbl[z]);
contED = EDcurr.ToString();
z++;
svSub = Convert.ToInt32(NotUsedTbl[i]);
z++;
svGrand = Convert.ToInt32(NotUsedTbl[z]);
}
}
MessageBox.Show(" total recs = " + NotUsedTbl.Count);
MessageBox.Show(" total recs = " + RetNotUsed.Count);
return RetNotUsed;
}
}
}
JB