这段代码怎么可能
TaskManager.RunSynchronously<MyObject>(fileMananager.BackupItems, package);
导致编译错误
The call is ambiguous between the following methods or properties:
'TaskManager.RunSynchronously<MyObject>(System.Action<MyObject>, MyObject)' and
'TaskManager.RunSynchronously<MyObject>(System.Func<MyObject, bool>, MyObject)'
当动作的签名是
public void BackupItems(MyObject package)
和“模棱两可”的方法是
static class TaskManager
{
public static void RunSynchronously<TInput>(Action<TInput> task, TInput param)
{
Task.Factory.StartNew(() => task(param));
}
public static bool RunSynchronously<TInput>(Func<TInput, bool> task, TInput param)
{
return Task.Factory.StartNew(() => task(param)).Result;
}
}
在我看来,这些方法之间存在很大差异。我在这里想念什么?
编辑:
除了接受的答案之外,我刚刚在类似问题中遇到了一个解决方案。这是链接。