如何将EventArgs e作为参数传递给T1.Start();? [英] How do pass EventArgs e as parameter in T1.Start();?

查看:149
本文介绍了如何将EventArgs e作为参数传递给T1.Start();?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar==(char)Keys.Space)
            {
                Thread T1 = new Thread(new ParameterizedThreadStart(Form1_KeyPress));
                T1.Start(sender,e);
                for (int i = 0; i < 300;i++ )
                {
                    Thread.Sleep(100);
                    pictureBox2.Left++;
                }
                T1.Abort();

            }
        }

推荐答案

我似乎找不到任何会启动的方法接受2个参数。你可以看一下 Threading.Thread [ ^ ]类并查找任何可以接受2个参数的方法。



答案,它不能通过,您可以将sender(Object)或e(Event)传递给方法。 Start只接受一个argumnt传递。
I don't seem to find any Start method that would accept 2 parameters. You can have a look at the Threading.Thread[^] class and look for any method that would accept 2 parameters.

Answer, it can't be passed, you can either pass the sender (Object) or the e (Event) to the method. The Start accepts only one argumnt to be passed down.


你没有。

EventArgs是作为Start方法处理的一部分为你创建的,发送到事件处理程序。您需要创建EventArgs实例的唯一时间是创建自己的事件并发送信号,以便处理程序可以正确使用它们。
You don't.
The EventArgs are created for you as part of the Start method processing, and sent to the event handler. The only time you need to create an instance of EventArgs is when you are creating your own events and signalling them so that handlers can work with them correctly.


这篇关于如何将EventArgs e作为参数传递给T1.Start();?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆