Application crashes with no error along with some very Strange behavior

I have an application that is crashing with no error message and it is doing some really strange things.

It is a Pocket PC application written using C# for the .NET Compact Framework

 Here is a code sample

                                          foreach(XmlNode nLabel in nlstLabel)
                                                sig1=(string)selectSingleNode(nUDFLabel, "sig_lab_1");
                                                sig2=(string)selectSingleNode(nUDFLabel, "sig_lab_2");
                                                Label1 = (string)selectSingleNode(nUDFLabel, "l_1");
                                                Label2 = (string)selectSingleNode(nUDFLabel, "l_2");
                                                Label3 = (string)selectSingleNode(nUDFLabel, "l_3");
                                                Label4 = (string)selectSingleNode(nUDFLabel, "l_4");
                                                Label5 = (string)selectSingleNode(nUDFLabel, "l_5");
                                                                /* NOTE THIS SPACE 11 */

                                          /* NOTE THIS SPACE 22 */

                                          SqlCeCommand sqlUDF = ssceconn.CreateCommand();
                                          sqlUDF.CommandText = insertStatement;

I knew it was crashing around here because after checking the database I realized the the sqlUDF command was never executing because the table was empty.  

The strage behavior comes in here.  Since I was getting no error message or Exception (which is caught) I started putting in MessageBox.Show(); statements to see which line was causing the problem.  When I put these statements in the application worked fine and all database table had proper data.  A friend said this used to happen to him in VB and its better to print to a file because MsgBox can change the way an application executes code.  So I printed to a file and the application still worked.  Even if I just open a file stream at the begining of this whole method and dont print anything to the file everything still works.  

So I started working backwards.  When I put in a MessageBox.Show() in the space marked /* NOT THIS SPACE 22 */ The message never appeared and the application crashed.  SO I thought, it must be happening in the for each loop.  So  I put a MessageBox.Show() in the space marked /* NOT THIS SPACE 11 */ and when I ran the application I saw the message appear and the application never crashed.  Since this for each loop always only has one iteration I assume it must be crashing when it reads the for each statement for the last time.  But why is it not crashing all the time?  How come opening a file or showing a message box before that line of code causes the application to work properly?  Also, if I step through the code in Debug mode, debuging from the device, the application runs fine.

Another note, this application was tested and released and has been working for the past 2 years.  I recently made an update to some code that has nothing to do with this code and when I recompiled It started crashing in this method.  I even viewed the differences between the files before and after I made the update and no changes were made to that code.    

So I guess my questions are:  Is it possible to find an error message somewhere in the system (Windows Mobile)?  Has anyone experiences this type of strange behavior before?  Do you have any suggestions on how to resolve this problem?

Any suggestions would be greatly appricated.  I am heading into day 4 trying to fix this problem and I'm losing hope.  I could open a file stream and that should fix the problem but that does not seem like a good solution to me.  As I leave you Im going to see if any compile paramters were changed, even though I never touched them.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel Van Der WerkenIndependent ConsultantCommented:
Well, use the try/catch phrases to see if you can catch an exception.  I know you say no exception is being produced, but I don't see a try/catch.

Second, it could be a timing issue.  Try using this:

using System.Threading;

and where you have the message box, try putting in a 1 sec sleep:


see if that helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alzoid69Author Commented:
I only displayed part of the method.  The whole method has a Try/Catch block around it.  I will try the timer and let you know if that works.


Did you try looking in the event log?

another thing I've done during development is set it up so any unhandled exceptions will be displayed

         // add this code in your startup method.
         Application.ThreadException+=new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

        private void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
            // or
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

alzoid69Author Commented:
Thanks Dan7el,

I have a few more questions about this issue if you have time to answer them.

What is a timing issue?  I am familiar with Threads (mostly in Java) but I have never encountered an error like this before.

I am not to familar with the .NET Framework but why would waiting a second help?  The code should execute the same way even if I halt it for a second.  Is there something else going on while my code is executing?


Daniel Van Der WerkenIndependent ConsultantCommented:
I wish I had an answer.  I've had a similar problem.  I assumed the wait fixed it?  Glad to hear it.  The root cause could be any one of a myriad of problems.  I wish I understood them all.

alzoid -

I noticed the code in question relates to a SQL function.

Have you made any changes at all to the database, or are you connecting in a different way than the app connects during construction or previous development?
alzoid69Author Commented:

Yes the Timer fixed the problem.  Thanks.

I could not find any logs on the Windows Mobile OS.  I am not familar with it.

That exception code is interesting, I think I may use it in the future.

No.  The database table in question was not changed.  The crash was occuring before the SQL Connection was opening.

Thanks everyone for your suggestions.  It's a good way to end off my Friday :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.