exit with escape key in for loop

后端 未结 1 1081
鱼传尺愫
鱼传尺愫 2021-01-27 05:29

I have this loop and is working :

  for (int x = 0; x < nombres.Length; x++)
            {
                ValidXX.Text = x.ToString(); ValidXY.Text = nombre         


        
相关标签:
1条回答
  • 2021-01-27 06:09

    you could do like this:

        bool escPressed = false;
    
            ....
            //run your loop in a different thread
            Thread thread = new Thread(new ThreadStart(MyLoop));
            thread.Start();
            ....        
    
    
        void MyLoop()
        {
            for (int x = 0; x < nombres.Length; x++)
            {
                if(escPressed) break;
                ValidXX.Text = x.ToString(); ValidXY.Text = nombres.Length.ToString();
    
                origen = nombres[x];
                cambia = nombres[x];
                pedrito = control.ValidarDocumentoXML(cambia);
                if (pedrito == true)
                { }
                else
                  /*  File.Move (origen , destino );*/
                try
                { }
                catch(IOException iox)
                {  MessageBox.Show(iox.Message); }
                { /* corrupto[x] = cambia; */ MessageBox.Show("malo" + cambia); }
            } 
        }
    
        private void Importar2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape) { escPressed = true;}   
        }
    
    0 讨论(0)
提交回复
热议问题