我目前正在按照数据服务模式在 WPF/MVVM 中进行开发,其中ViewModel调用包含所有业务对象和方法的服务。
现在,当我调用服务方法时,这需要一些时间,所以我应该创建一个新任务,以使 GUI 不会冻结。
在您看来,在 ViewModel 中还是在 Service 本身中,启动任务的最佳位置在哪里?
...
// TaskFactory.StartNew(() => {}); // where I should put this ? *
...
class DataService
{
MyBussObj mbo;
CallBusinessOperation()
{
// * here ?
while (mbo.Next())
{
// requires a while
}
}
}
class MyViewModel
{
DataService service = new DataService();
void DoIt()
{
// * here ?
service.CallBusinessOperation();
}
}