![](/img/trans.png)
[英]Blazor pass and run Task from child component - cannot convert from 'method group' to 'Task<int>'
[英]Pass Task as a Parameter in C# get me cannot convert from 'method group' to 'Task'
我有这个创建启动画面的方法
public static async Task CreateSplashScreen(Task action, Form form, string description)
{
var splashScreenManager = new SplashScreenManager(form, typeof(WaitForm1), true, true)
{
SplashFormStartPosition = SplashFormStartPosition.CenterScreen,
};
splashScreenManager.ShowWaitForm();
splashScreenManager.SetWaitFormDescription(description);
await action;
splashScreenManager.CloseWaitForm();
splashScreenManager.Dispose();
}
这是一种创建和预览报告的方法
public static async Task CreateBlackProductionProjectReport()
{
using RepCharpenteProductionByShiftTime report = new();
SmartHelpers.AddDateRangeShiftTimeQueryParameter(report.sqlDataSource1.Queries[0].Parameters);
SmartHelpers.AddDateRangeParameter(report);
await SmartHelpers.AddShiftTimeParameter(report);
report.ShowRibbonPreviewDialog();
}
单击按钮时,我会像这样调用 CreateSplashScreen 方法
private async void ShowBlackProductionProjectReport(object sender, ItemClickEventArgs e)
{
await CreateSplashScreen(CreateBlackProductionProjectReport,
this,
ReportDescription);
}
我收到了这个错误
无法从“方法组”转换为“任务”
我尝试使用 Action 而不是 Task 作为参数
public static void CreateSplashScreen(Action action,Form form, string description)
但我得到了
'Task CreateBlackProductionProjectReport()' 的返回类型错误
我错过了什么,我该如何解决?
您的第一次尝试几乎是正确的,您只是错过了一对括号:
对于以下签名:
public static async Task CreateSplashScreen(Task action, Form form, string description)
调用看起来像:
private async void ShowBlackProductionProjectReport(object sender, ItemClickEventArgs e)
{
await CreateSplashScreen(CreateBlackProductionProjectReport(),
this,
ReportDescription);
}
没有它们,您将传递可能被同化为Func<Task>
的内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.