Visual Studio application exited with code -1 (0xffffffff), application is not responding

-3

My Windows Forms application run after debug normally, but when I press start button, it goes not responding, and when I stop debugging, output log says it exited with code -1 (0xffffffff). I am using Visual Studio 2017 Community v. 15.7.14. and .NET framework 4.7.03056. Can someone find bug or else reason why it is not working? Code:

{
   public partial class Form1 : Form
{
    static Timer myTimer = new Timer();

    bool pokus1;
    bool pokus2;
    bool pokus3;
    bool pokus4;
    bool pokus5;
    double h = 0;
    double v;
    ulong t;
    double hmotnost;
    double F;
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string polomer = textBox1.Text;
        string m = textBox2.Text;
        string p = textBox3.Text;
        string nv = textBox4.Text;
        string T = textBox5.Text;
        double r;

        ulong tlak;
        ulong vyska;
       double teplotac;
        double hustotaV = 1.29;
        double m_p = 0;


        int rS = trackBar1.Value;

        myTimer.Interval = (1000 - (rS * 100));
        myTimer.Start();
        v = 0;

        pokus1 =  Double.TryParse(polomer,out r);
        if (!pokus1) //here I want secure "Non-number" inputs
        {
            MessageBox.Show("Zadejte kladnou hodnotu v metrech, menší než ulong");
        }
        pokus2 = Double.TryParse(m, out hmotnost);
        if (!pokus2)
        {
            MessageBox.Show("Zadejte kladnou hodnotu v kilogramech, menší než ulong");
        }
        pokus3 = UInt64.TryParse(p, out tlak);
        if (!pokus3)
        {
            MessageBox.Show("Zadejte kladnou hodnotu v pascalech, menší než ulong");
        }
        pokus4 = UInt64.TryParse(nv, out vyska);
        if (!pokus4)
        {
            MessageBox.Show("Zadejte kladnou hodnotu v metrech, menší než ulong");
        }
        pokus5 = Double.TryParse(T, out teplotac);
        if (!pokus5)
        {
            MessageBox.Show("Zadejte kladnou hodnotu ve stupích Celsia, menší než long");
        }
        else
        {
            if (H_BTN.Checked == true)
            {
                m_p = 0.0899 * ((4 / 3) * Math.PI * Math.Pow(r,3));
            }
            else if (He_BTN.Checked == true)
            {
                m_p = 0.179 * ((4 / 3) * Math.PI * Math.Pow(r,3));
            }
            while (h <= 35000)
            {
                double Dvm;
                double Dv;
                double teplota = teplotac + 273.149806372;
                Dvm = 2.75874 + 0.0598528 * teplota - 2.626e-5 * teplota * teplota + 5.22e-9 * teplota * teplota * teplota;
                Dv = (Math.Round(Dvm * 1e3)) / 1e3;
                string vD = Dv.ToString();
                label9.Text = vD;
                double Ov = 6 * Math.PI * Dv * v * r;
                label12.Text = Ov.ToString();
                double Fvz = ((4 / 3) * Math.PI * r * r * r) * hustotaV * 9.81;
                hmotnost = hmotnost + m_p;
                double Ft = (hmotnost) * 9.81;
                F = Fvz - Ft - Ov;



            }
        }


    }



    private void timer1_Tick(object sender, EventArgs e)
    {
        t++;
        v = Math.Sqrt(Math.Abs((F * 35000)) / hmotnost);
        h = v * t;
        label15.Text = v.ToString();
        label16.Text = h.ToString();
        string h_c = h.ToString();

        int h_v;
        bool odp = Int32.TryParse(h_c, out h_v);
        progressBar1.Value = h_v;


    }

    private void H_BTN_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        myTimer.Stop();
    }
}

}

Form 1

c#
.net
visual-studio
winforms
asked on Stack Overflow Jul 4, 2018 by dejf • edited Jul 4, 2018 by dejf

1 Answer

-1

There are 2 issues with your code that are causing this problem:

  1. I don't see myTimer.Tick += timer1_Tick; anywhere
  2. You are running everything on the UI thread and because of this timer.Tick is never hit. I would suggest running the while loop on a separate thread

        Task.Run(() =>
        {
            while (h <= 35000)
            {
                ...
            }
        });
    

You could have found this easily by debugging so if you are new to Visual Studio I suggest learning how to debug your top priority.

answered on Stack Overflow Jul 4, 2018 by Igor Meszaros • edited Jul 4, 2018 by Igor Meszaros

User contributions licensed under CC BY-SA 3.0