实例化委托的参考?

时间:2013-07-06 11:25:48

标签: c# multithreading pointers reference

private void ShakeWindow()
    {
        Thread thread = new Thread(new ThreadStart(() =>
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new Action(/* ref to this instantiated method? */), null);
                }
                else
                {
                    // shake window
                }
            }));
         thread.Start();
    }

我可以通过上面提到的参考吗?怎么样?或者有没有更好的解决方案来调用控件?我知道我可以通过以下方式做到这一点:

private void ShakeWindow()
    {
        Thread thread = new Thread(new ThreadStart(ShakeWindowThread));
        thread.Start();
    }
    private void ShakeWindowThread()
    {
        if (this.InvokeRequired)
        {
            this.Invoke(new Action(ShakeWindowThread), null);
        }
        else
        {
            // shake window
        }
    }

0 个答案:

没有答案
相关问题