473,388 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

ContextSwitchDeadlock error, index out of range and < size collect

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
Nov 13 '08 #1
1 2981
On Thu, 13 Nov 2008 10:59:01 -0800, JB <JB@discussions.microsoft.com>
wrote:
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. [...]

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?
You can safely ignore the first error, assuming it only happens when you
are stepping through code in the debugger. The act of doing so
necessarily causes other threads (which are also suspended when you're
just sitting there interrupted in the debugger) to not be able to work.
Sometimes that causes the delay that sets off that warning.

As for the second error, you need to look at your code when the exception
happens and see why you are passing an index that's out of range.
Obviously, it would be invalid to pass an index to a collection that is
nothing within the range of valid indices for the elements in that
collection.

The code you posted is neither concise nor complete, so I'm not going to
spend any time trying to figure out why your "z" index winds up larger
than the maximum valid index for the "NotUsedTbl" list instance. But
suffice to say, it is and that's exactly what that exception is telling
you.

Pete
Nov 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew V. Romero | last post by:
I have a script that I am working on for an intranet tool and in this script I have a form, which when submitted the onSubmit command calls calculate(). In this calculate function, I have it do...
2
by: B_Love | last post by:
Hey! When trying to compile the code for a ordered vector class I get the following error: undefined reference to `WinMain@16' Anyone have any idea what I might be doing wrong? I've been...
14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
2
by: kscdavefl | last post by:
When I run the following code: private void applicationPermissionGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType ==...
1
by: Clark Choi | last post by:
I ran the sample application called Petstore from msdn. Everything went fine until I tested Update button on the web form to update the database through Datagrid. I have been searching the web to...
11
by: Andrew Poelstra | last post by:
I hammered this out this morning to fix inconsistancies with the way my programs handle errors. The code itself is fine, in that it compiles with Richard Heathfield's gcc tags (plus -c because it...
0
by: zfraile | last post by:
I'm getting this error from the JIT compiler at runtime, but only on my boss' machine, not my development machine. I believe the error is generated from a call to an Excel object, but I can't tell...
4
by: Abdhul Saleem | last post by:
Hi, I am recieving error ActiveX component can't create object in the following line in the asp page. set ExcelApp = CreateObject("Excel.Application") Previously this code was working fine....
1
by: morrisqueto | last post by:
Hello, One of my websites just started sending a new rare error. The site has been working for almost 2 years without trouble, but today morning started giving away this error in all my views. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.