C# Atlassian.NET SDK异步方法不';t抛出异常
编辑: 以下是异步方法:C# Atlassian.NET SDK异步方法不';t抛出异常,c#,async-await,C#,Async Await,编辑: 以下是异步方法: string summary = "TestIssue"; string description = "TestDescription"; string type = "Task"; string projectKey = "TST"; string priority = "p - 3"; Task<string> created = createIssue(summary, description, type, priority, projectKey)
string summary = "TestIssue";
string description = "TestDescription";
string type = "Task";
string projectKey = "TST";
string priority = "p - 3";
Task<string> created = createIssue(summary, description, type, priority, projectKey);
在这里,我得到一个异常,它告诉我实际的问题:
{“未找到类型为“Atlassian.Jira.IssuePriority”的id为“”且名称为“p-3”的实体。可用:[10000:p-310001:N/A,4:p-4,3:p-2,2:p-1,1:p-0]”}
是否可以在异步方法中捕获这些类型的异常?我需要创建处理程序还是执行其他操作 您使用
.Result
阻塞UI线程,意外地造成了死锁
请参阅此讨论
将按钮处理程序更改为async,并在其中使用Wait。另外,删除
createIssueWrapper
-您不需要它。Task created=…
您在哪里等待呼叫?嘿,谢谢,这就解决了问题。我不知道我需要将await添加到调用中,并用异步方法将其包装。您可能需要阅读@StephenCleary async/await介绍性文章,以及该博客上任何与async/await相关的博客文章,但仍有问题。我向一个异步方法添加了“taskcreated”调用,并返回该调用的结果。从main方法调用异步包装器方法。。但是当它到达那里时,如果我在“var jiraIssue=wait issue.SaveChangesAsync();”行上添加一个断点,它就没有结果了它可以工作(因为有延迟)。如果我删除它,它将进入我的主方法,而不会产生结果
string summary = "TestIssue";
string description = "TestDescription";
string type = "Task";
string projectKey = "TST";
string priority = "p - 3";
Task<string> created = createIssue(summary, description, type, priority, projectKey);
public async Task<string> createIssue(string summary, string description, string type, string priority, string projectKey)
{
string key = "";
try
{
var issue = jira.CreateIssue(projectKey);
issue.Type = type;
issue.Priority = priority;
issue.Summary = summary;
issue.Description = description;
var jiraIssue = await issue.SaveChangesAsync();
if (jiraIssue != null)
{
key = jiraIssue.Key.ToString();
}
}
catch (Exception ex)
{
}
return key;
}
var issue = jira.CreateIssue(projectKey);
issue.Type = type;
issue.Priority = priority;
issue.Summary = summary;
issue.Description = description;
issue.SaveChanges();