如何在后台工作程序中调用此方法?

时间:2016-07-19 10:49:50

标签: c# wpf

我是C#和WPF的初学者,我正在构建这个项目,我必须在鼠标移动时触发。在某些情况下,我必须将它用作后台工作者。我想在后台调用mouse_Moved方法,但我不知道如何实际执行此操作。有人可以帮我吗?到目前为止,这是我的代码:

public MainWindow() 
{
   InitializeComponent();

   mouse = new MouseInput();
   mouse.MouseMoved += mouse_MouseMoved;

}
void mouse_MouseMoved(object sender, EventArgs e)
{
    //The code that I need
} 

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
   //where I want to call the mouse_Moved method
}

1 个答案:

答案 0 :(得分:2)

创建一个方法并从以下两个方法调用它:

void mouse_MouseMoved(object sender, EventArgs e)
{
    DoMouseMovedWork();
}

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
    DoMouseMovedWork();
}

private DoMouseMovedWork()
{
    //The code I need
}