Code fails to execute - no error, and program keeps running

  • Thread starter Thread starter BoloBaby
  • Start date Start date
B

BoloBaby

I have an extremely vexing problem occurring in a program that I am writing.
Consider the following block of code:

Dim pDancer As New BEDancer
mintIndex = mintIndex + 1
pDancer.DancerName = "Dancer #" & mintIndex
pDancer.DancerStatus = BEDancerStatus.BE_AVAILABLE
pDancer.CardID = mintIndex
oBEDancerList.AddDancer(pDancer)

....where BEDancer is a user defined class in a referenced class library,
mintIndex is a class level variable, and oBEDancerList is a user control
defined in a referenced control library.

When I place this code (and only this code) into the event handler for the
click event of a button on a form, it executes flawlessly - the BEDancer
gets added to the BEDancerList control without any complications.
HOWEVER...

When I place this code (and only this code) into the event handler for the
"CardInserted" event in a user defined class (which is instantiated in the
code for the form), the code executes up to the line "pDancer.CardID =
mintIndex" and NO FURTHER. Beyond that, the code simply STOPS EXECUTING.
If I place additional code after the AddDancer method, it doesn't execute.
No errors are thrown - it just stops. If I comment out the
"oBEDancerList.AddDancer(pDancer)" line, code past it will execute just
fine.

Why would this block of code work fine for a click event but not for the
event raised by my custom class? The custom class does not reference the
BEDancerList control library in any way. It uses the BEDancer class from a
shared class library. In fact, the files look like this:

BEGlobals.dll <- location of BEDancer
BEControls.dll <- location of BEDancerList control
BELib.dll <- location of the class which raises the "CardInserted" event
BEDJApp.exe <- main app that is running it all

The latter three files all reference BEGlobals.dll, if that matters.

Finally, I can still access the oBEDancerList control from the
"CardInserted" event handler. I can display the oBEDancerList.DancerCount
property or even call the oBEDancerList.RemoveDancer method. I just can't
AddDancer! Very, very troublesome indeed.

In case you want to see this, the AddDancer code looks like this:

Dim pDancerBox As BEDancerBox
pDancerBox = New BEDancerBox(Dancer)
AddHandler pDancerBox.Clicked, AddressOf DancerBoxClicked
AddHandler pDancerBox.StatusChanged, AddressOf StatusChanged
pnlDancerList.Controls.Add(pDancerBox)
Reorder(pnlDancerList.Controls.Count - 1)

I tried commenting out the AddHandler lines in case something funky was
going on there, but that didn't make any difference. As you may be able to
tell from this code, the AddDancer method is adding BEDancerBox controls
into a panel control.

Any thoughts?

(Oh yeah - as you may be able to tell, this is an application for a... uh...
"gentlemen's club." If you can help - and are local - I can probably hook
you up with a free couch dance! LOL! ;-))
 
Hi BoloBaby,

My first thought is, that you say that it stops on the
pDancer.DancerName = "Dancer #" & mintIndex

So what is this (I asume) property

And your offer I have no intrest at all, I am grown up in an area of the
world where that is mostly for the tourists.

:-)

Cor
 
That property is simply a string that stores the dancer name. (Later it
will be filled from a database, but for now I'm just putting a pseudo-value
in there.)

This property has no special processing in the Get and Set statements. Just
value assignment to a string variable.

This line of code works flawlessly when it is called from the button's click
handler. Also, that is the last line of code to execute. In other words,
it actually performs that line of code without any problems. It is the NEXT
line of code that fails to execute.

What really bothers me here is that the code simply fails to execute. It
doesn't throw an error or cause a runtime error - it just stops executing.
The program still runs, but if I try to raise that event again, it fails to
execute at the same exact line... a line of code that works just fine from a
button's click handler. It just doesn't make any sense...
 
Hi BoloBaby,

What is than in that next line, I really though from you text that it
stopped in the line you said,

BEDancerStatus.BE_AVAILABLE

What is that?

Cor
 
I've actually traced the code down to the exact line it fails. This occurs
when attempting to add a custom control to a panel control during the
AddDancer method.

Is the panel control bugged? Is this a known issue?
 
The code fails to execute during this line -
"oBEDancerList.AddDancer(pDancer)"

I traced the execution into that method. The code within that method works
great up until it gets to:

"pnlDancerList.Controls.Add(pDancerBox)"

....which is when I attempt to add a "BEDancerBox" control to my panel
control. That is where it fails. It doesn't throw an error, it just stops
executing.

This must have something to do with the panel control and adding controls to
it during runtime....
 
Cor,

I distilled the code down to a really simply skeletal version of the code.
I don't use any custom controls or anything - just a form, a button, a panel
control, and my custom event.

I posted a new question under the title "Bug in .NET panel control? Or am I
missing something?"

I felt that the issue was probably getting confused by my use of custom
classes and controls - so I cut it down to the absolute basics. Check out
that thread for a clearer picture of what is happening.

Gardner
 
I posted complete source code for the streamlined app under that alternate
thread. It is very short, but demonstrates that something strange is
happening....
 
Back
Top