【发布时间】:2014-04-23 00:55:07
【问题描述】:
我想定义一个虚方法,它在基类中不是异步的,但在派生类中是异步的,调用者使用委托调用它(实际上它是由屏幕上的按钮激活的 ICommand)我怎么能这样做。
public class BaseClass
{
BIONESSBindingCommand mLogoffCommand;
public ICommand LogoffCommand
{
get
{
if (mLogoffCommand == null)
{
mLogoffCommand = new BIONESSBindingCommand(
Param => Logoff(), //Command DoWork
Param => true); //Always can execute
}
return mLogoffCommand;
}
}
public virtual Task Logoff()
{
DoLogoff();
return null; //???
}
}
public class DerivedClass : BaseClass
{
public override async Task Logoff()
{
await SomeWoAsyncWork();
base.Logoff(); //Has warninngs
}
}
【问题讨论】:
-
难道你正在做的事情不正常吗(除了在构造函数中指定属性和方法)?
标签: c# asynchronous windows-runtime task-parallel-library async-await