Action in C# 3.0
I am coding a C# .NET 3.0 asynchronous call to a WCF service. And I get the following error.
Error 1 开发者_如何学运维Using the generic type 'System.Action' requires '1' type arguments.
But when doing this in .NET 3.5 no error occurs. Doesn't .NET 3.0 support this or I am doing wrong. I have to use .NET 3.0 because iam writing a application for XPe.
This is how my code looks like.
AsyncCallback aSyncCallBack =
delegate(IAsyncResult result)
{
try
{
service.EndSubscribe(result);
this.Dispatcher.BeginInvoke((Action)delegate
{ DGStudent.ItemsSource = test; });
}
catch (Exception ex)
{
this.Dispatcher.BeginInvoke((Action)delegate
{ MessageBox.Show(ex.Message); });
}
};
The non-generic System.Action
was introduced in .NET 3.5 and cannot be used from .NET 3.0. The compiler thinks you mean the generic System.Action<T>
which does require a type parameter.
All the Action
delegates apart from Action<T>
were only added in .NET 3.5; they're not available in 3.0. If you have a look at the documentation, the Action
documentation only has versions for 3.5 and 4.0, whereas the Action<T>
documentation goes back to 2.0.
You'll have to create your own version of a no-args delegate, or use something similar like MethodInvoker
in winforms.
精彩评论