Geeks With Blogs

News

Google My Blog

Catch me at: The List!


My InstallScript Utility Belt My Amazon Wishlist
My Standard Disclaimer


Archives
Chris G. Williams Beware: I mix tech and personal interests here.
Can someone please explain this to me?

I have a class that contains a loop that should execute anywhere from 8 to 12 times (it's random.)
In this loop, I set some values in a two dimensional array.
I have a test program (a console app) that uses this class, executes this loop, and displays the results.

Here's where it gets weird...

If I run the test program with no breakpoints, it displays results that indicate the loop is only running once (or VERY RARELY twice)
If I set breakpoints and step into the class, I can see the loop is running somewhere between 8 and 12 times, and it displays the proper results in the test program!!

Can anyone tell me why my program would not work properly when running, but work fine when stepping through the code? This is making me slightly crazy. Posted on Saturday, November 26, 2005 10:54 PM Game Development , General Interest | Back to top



Comments on this post: Adventures in C#, continued...

# re: Adventures in C#, continued...
Requesting Gravatar...
You probably missed out some semi colons :-)

You should post the code (or email it to me) - hard to guess what is going on.
Left by ZMan on Nov 26, 2005 11:10 PM

# re: Adventures in C#, continued...
Requesting Gravatar...
fine fine... check your email. :)

Left by Chris Williams on Nov 26, 2005 11:45 PM

# re: Adventures in C#, continued...
Requesting Gravatar...
I'm totally spitballing here but doesn't the random function behave differently in debug mode and in release mode?
Left by Codesailor on Nov 27, 2005 6:36 AM

# re: Adventures in C#, continued...
Requesting Gravatar...
I would certainly hope not... Even if it did, I should still be getting a minimum of 8 iterations, and as many as 12. I'm only getting 1 (and rarely 2).

Besides, I'm in debug either way... I'm just hitting F5 to run it. It works with breakpoints, but not without. STRANGE!!
Left by Chris Williams on Nov 27, 2005 8:00 AM

# re: Adventures in C#, continued...
Requesting Gravatar...
If it helps anyone, this is what I have installed:

Microsoft Visual Studio 2005
Version 8.0.50727.26 (RTM.050727-2600)
Microsoft .NET Framework
Version 2.0.50727
Left by Chris Williams on Nov 27, 2005 8:09 AM

# re: Adventures in C#, continued...
Requesting Gravatar...
Post you code! Nobody's going to be able to help you if you don't post your code.
Left by Joseph Hachey on Nov 27, 2005 4:43 PM

# re: Adventures in C#, continued...
Requesting Gravatar...
Hello Chris,
I think this has something to do with the testing way itself. I mean the dependancy that tells you the the loop is executed. I don't think you've tried to write to the Console directly from the loop for once (I guess if you do once without breakpoints, you'll find it still executes the right number of times relevant to the random). I think you mostly depend on the array in some wrong way to tell whether the loop has been performed.
Whether I was right or wrong. I agree with all the other geeks over here. You still need to send the code for further help, or at least a similar code snippet that explains your problem.
Regards,
Left by Mohamed A. Meligy on Nov 27, 2005 11:45 PM

# re: Adventures in C#, continued...
Requesting Gravatar...
Hi Chris,
I guess its more to do with the random number generation algorithm you are using than the loop. If you are using something in the Random class, then try the one in the cryptography class. It would be really helpful if you can post the code.

Regards,
Sidhu
Left by IamJunk on Nov 28, 2005 1:55 AM

# re: Adventures in C#, continued...
Requesting Gravatar...
Actually, the ZMan figured it out.

The constructor of my random was using a time based seed and because I was accidentally reseeding it with each call, it was running so fast that the numbers being generated were largely the same.

When stepping through the code, this wasn't a problem.

So a big Thank You to the ZMan for figuring it out.
Left by Chris Williams on Nov 28, 2005 4:35 AM

# re: Adventures in C#, continued...
Requesting Gravatar...
I was just coming to post that. I have run into this half a dozen times.....
Left by Rick on Nov 28, 2005 6:23 AM

# re: Adventures in C#, continued...
Requesting Gravatar...
I'm still intrigued by this. Any chance you can expand on this with a short code sample that shows the problem. Since it has been solved I would love to see how it all started and how to avoid it myself.
Left by Eric Hammersley on Nov 29, 2005 8:06 AM

# re: Adventures in C#, continued...
Requesting Gravatar...
I can do that, but it might be a few days before I get a chance. I'm pretty slammed this week.
Left by Chris Williams on Nov 29, 2005 8:32 AM

Your comment:
 (will show your gravatar)


Copyright © Chris G. Williams | Powered by: GeeksWithBlogs.net