Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 退出,退出循环中的退出键_C#_Visual Studio 2010 - Fatal编程技术网

C# 退出,退出循环中的退出键

C# 退出,退出循环中的退出键,c#,visual-studio-2010,C#,Visual Studio 2010,我有这个循环并且正在工作: for (int x = 0; x < nombres.Length; x++) { ValidXX.Text = x.ToString(); ValidXY.Text = nombres.Length.ToString(); origen = nombres[x]; cambia = nombres[x];

我有这个循环并且正在工作:

  for (int x = 0; x < nombres.Length; x++)
            {
                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); }
            } 

但是我无法将此键写入for循环。

您可以这样做:

    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;}   
    }
bool escPressed=false;
....
//在不同的线程中运行循环
线程线程=新线程(新线程开始(MyLoop));
thread.Start();
....        
void MyLoop()
{
对于(int x=0;x
在线程中运行逻辑或整个for。在KeyDown事件中,告诉线程停止。
    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;}   
    }