简体   繁体   English

Dispatcher.Invoke在vs2010中工作但在vs2008中给出错误

[英]Dispatcher.Invoke working in vs2010 but giving error in vs2008

I have to submit my WPF project tomorrow morning; 我必须明天早上提交我的WPF项目; it is running perfectly in VS 2010 but giving error in VS 2008 (.NET 3.5 in both case) using C#. 它可以在VS 2010中完美运行,但在使用C#的VS 2008(两种情况下均为.NET 3.5)中都会出错。

I am using a timer using Dispatcher.Invoke but in VS 2008 it is giving error : 我正在使用使用Dispatcher.Invoke的计时器,但是在VS 2008中,它给出了错误:

Error 163 错误163
The best overloaded method match for System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate) has some invalid argument. System.Windows.Threading.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority, System.Delegate)的最佳重载方法匹配具有一些无效的参数。

The below code is giving the error: 下面的代码给出了错误:

Dispatcher.Invoke(new Action(() =>
{
    // ANY ACTIONS HERE
    .. some task
}), null);

The code must work in VS 2008. 该代码必须在VS 2008中工作。

It sounds like the VS 2008 build is targeting .NET 3.0, not 3.5. 听起来好像VS 2008内部版本针对的是.NET 3.0,而不是3.5。 The overload you're using was added in .NET 3.5, and the error message suggests that .NET 3.0 is being found. 您正在使用重载已添加到.NET 3.5中,并且错误消息表明已找到.NET 3.0。

You could easily rework the call to work using the 3.0 overload via: 您可以通过以下方式使用3.0重载轻松重做调用以使其正常工作:

Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
   {
      // ...some task
   }));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM