关注Jason Dolinger视频我已经装扮了装饰普通模型的DispatchingWcfModel。但我不明白为什么我需要它。我应该总是使用某种调度模式?如果我将使用普通模型而不是调度模型呢?为什么我需要“调度员”?何时在mvvm中使用Dispatcher?
class DispatchingWcfModel : IWcfModel
{
private readonly IWcfModel _underlying;
private readonly Dispatcher _currentDispatcher;
public DispatchingWcfModel(IWcfModel model)
{
_currentDispatcher = Dispatcher.CurrentDispatcher;
_underlying = model;
_underlying.DataArrived += _underlying_DataArrived;
}
private void _underlying_DataArrived(List<ConsoleData> obj)
{
Action dispatchAction =() =>
{
if (DataArrived != null)
{
DataArrived(obj);
}
};
_currentDispatcher.BeginInvoke(DispatcherPriority.DataBind, dispatchAction);
}
public List<ConsoleData> DataList
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public event Action<List<ConsoleData>> DataArrived;
}
我想你最好给Jason的视频添加一个链接。我想大多数人都没有看到它,并且可能没有考虑到他必须实现这样一个ViewModel的原因。现在对我来说(我没有看过视频)我认为这个ViewModel是没有意义的。 – Snowbear
由于某种原因,此视频暂时无法使用,请点击此处http://blog.lab49.com/archives/2650 – javapowered