I try to develop the program with C# VS in Windows Mobile5.0
My application up and running, however when I scan the barcode and get the data from database it work fine.
Once I keep scan the barcode for a while. Program stop working and sometime can be terminate as StackOverflow.
I always do this before I open the new form.
This.close

Please help.

Without seeing any code how could we possibly know what is causing the issue? Post the code where the problem is happening.

Here is the error that it generated to me.
Once I get my code from another computer I will post it up.

Thank you very much for all of your help.

You could try adjusting the size of the stack for your application (if you can do that for C# mobile apps).

Probably a project setting option.

You say you call

This.close()

Are you also calling any relevant

This.Dispose()

?

I did not call

1. This.Dispose()

So do I need to call like this

This.close()
This.Dispose()

This is the code that I wrote before.

private void menuItem2_Click(object sender, EventArgs e)
        {
            if (comboBox2.SelectedValue != null)
            {
                this.barcode = comboBox2.Text;
                this.m_updateData = new updateData();
                this.m_updateData.Owner = this;
                this.m_updateData.Show();

                Application.DoEvents();

                m_updateData.Barcode = this.barcode;
                m_updateData.ShowDialog();

                this.Close();
            }
        }

I also would like to know what is the different between This.close and This.dispose please.

What line causes the stack overflow? Your image doesn't show any of the stack where your code is running.

Also, for almost every item in .NET, .Close() and .Dispose() do the same thing. Call .Dispose() just to be safe, but understand that calling this.Dispose() will cause your application to fail. What exactly are you trying to do in line 15 of the code above?

I don't agree with

Also, for almost every item in .NET, .Close() and .Dispose() do the same thing. Call .Dispose() just to be safe, but understand that calling this.Dispose() will cause your application to fail.

They are NOT the same. Dispose() automatically calls close, but that is as far as the similarities go. Close() is the same as Visible = False. It just hides the form, but the form takes up memory.

Dispose() releases the form. Basically, it frees all memory used by the form. This is NOT closing it. Think of it in terms of a newspaper. Close() just hides it from you. Dispose() actually removes it.

That being said, be careful to only call dispose when you won't be using the form again.

Notice I said "for almost every item". Try reading the .NET source sometimes, you'll find that all .Close() does is call .Dispose().

Also, from Form.Close(): When a form is closed, all resources created within the object are closed and the form is disposed. You can prevent the closing of a form at run time by handling the Closing event and setting the Cancel property of the CancelEventArgs passed as a parameter to your event handler. If the form you are closing is the startup form of your application, your application ends.

The two conditions when a form is not disposed on Close is when (1) it is part of a multiple-document interface (MDI) application, and the form is not visible; and (2) you have displayed the form using ShowDialog. In these cases, you will need to call Dispose manually to mark all of the form's controls for garbage collection.

In the line I pop up a new form to get the data from the database.
Then the old form need to be closed to save the memory and does not have the mutiple form open at the same time.

Thank you.

What I try to do is that
m_updateData.Barcode = this.barcode;
m_updateData.ShowDialog() // POP up the new form

this.Close(); // Close the new form

This will call the new form and then it will need to close the old form.
This prevent the issue for the memory.

Once I keep scanning the data and then at some point it crash.
and has the error as the picture above.

P.S. My program has to scan the barcode and then update the data from the SQL.
That why I did my program like this.
Get the barcode -> New Form to display the data -> then close the old one to prevent the memory issue.
But the StackOverflow error is happened.

Thank you very much for your help.

with

m_updateData.Barcode = this.barcode;
m_updateData.ShowDialog() // POP up the new form

this.Close(); // Close the new form

if you want to close the new form, you'd need to do this:

m_updateData.Barcode = this.barcode;
m_updateData.ShowDialog() // POP up the new form

m_updateData.Dispose(); // Close the new form

Thank you very much for all of your help.
I already changed the code into this

I did the comment wrong.

m_updateData.Barcode = this.barcode;
m_updateData.ShowDialog() // POP up the new form

this.Dispose(); // Close the old form since the new form has been open

It still give me and error.

I am not sure when I connecto the the CESQL I use this code

using (SqlCeConnection conn = new SqlCeConnection(connstr))
            {

                conn.Open(); // This already has the SQL Parameter

                string dmlPackageInfo = "SELECT FEX.oldBarcode, FEX.inspected, BUILDINGCODE.code, FEX.room, FEX.size, FEX.type, FEX.annual, FEX.comment, FEX.buildingId FROM FEX LEFT JOIN BUILDINGCODE ON FEX.buildingId = BUILDINGCODE.id WHERE FEX.oldBarcode = ?";
                SqlCeCommand cmdGetPackageInfo = null;
                SqlCeDataReader drPackageInfo = null;


                try
                {
                    bool flag = true;                    

                    cmdGetPackageInfo = new SqlCeCommand(dmlPackageInfo, conn);
                    cmdGetPackageInfo.CommandType = CommandType.Text;
                    cmdGetPackageInfo.Parameters.Add("FEX.oldBarcode", db_temp);
                    cmdGetPackageInfo.Prepare();



                    drPackageInfo = cmdGetPackageInfo.ExecuteReader(CommandBehavior.SingleRow);

                    while (drPackageInfo.Read())
                    {
                        //String temp = drPackageInfo.GetString(1);
                        String temp = drPackageInfo.GetDateTime(1).ToString("MM/dd/yyyy");
                        label11.Text = temp.Substring(0,10);
                        if (!drPackageInfo.IsDBNull(2))
                        {
                            building_code_temp = drPackageInfo.GetString(2);
                        }                        
                        textBox2.Text = drPackageInfo.GetString(3);
                        textBox3.Text = drPackageInfo.GetString(4);
                        textBox5.Text = drPackageInfo.GetString(5);
                        //String temp2 = drPackageInfo.GetDateTime(6).ToString("MM/dd/yyyy");
                        dateTimePicker1.Value = drPackageInfo.GetDateTime(6);
                        textBox8.Text = drPackageInfo.GetString(7);
                        if (!drPackageInfo.IsDBNull(8))
                        {
                            array_index = drPackageInfo.GetInt32(8);
                        }
                    }

                    int i = 0;
   
                }

                catch (SqlCeException scee)
                {
                    for (int curExNdx = 0; curExNdx < scee.Errors.Count; ++curExNdx)
                    {
                        System.Windows.Forms.MessageBox.Show(
                        "Error:" + scee.Errors[curExNdx].ToString() + "\n");
                    }
                }

                finally
                {
                    if (cmdGetPackageInfo != null)
                        cmdGetPackageInfo.Dispose();

                    if (drPackageInfo != null)
                        drPackageInfo.Close();
                }
                conn.Close();    // <----- This line should I change it to conn.dispose(); ????
            }

I really appreciate your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.