我的应用程序基本上是一个电子邮件客户端。它通常工作正常\xe2\x80\x94,没有问题或错误。当它向收件人发送电子邮件时,他们会成功收到该消息。然而,当该异步任务完成时,整个应用程序就会冻结。
\n\nawait我使用的修补程序是从 API 响应中删除关键字。这是可行的,但是使用这种方法,您无法获取确定消息是否已成功发送的状态代码,因为您没有等待响应。
这是代码:
\n\nusing System;\nusing System.IO;\nusing System.Linq;\nusing System.Threading;\nusing System.Threading.Tasks;\nusing SendGrid;\nusing SendGrid.Helpers.Mail;\n\nnamespace SendMailClass{\n internal class FunctionCall{\n\n #region Getting user info\n static bool EmailHasBeenSend = false;\n static string Documents = Environment.GetFolderPath(Environment.SpecialFolder\n .MyDocuments) + "\\\\Documents.txt";\n static string UserName = File.ReadLines(Documents).Skip(0).Take(1).First();\n static string UserEmail = File.ReadLines(Documents).Skip(1).Take(1).First();\n #endregion\n\n public static void SendFunction(string Recipient, string SubjectVariable,\n string CC, string BCC, String Messange,string FileName,\n string AttachmentPath)\n {\n Execute(Recipient, SubjectVariable ,CC,BCC, Messange ,FileName,\n AttachmentPath).Wait();\n }\n\n static async Task Execute(string Recipient, …Run Code Online (Sandbox Code Playgroud) 我有一个使用 SQL 命令与数据库交互的应用程序。命令之一是删除函数,语法正确,当我在数据库中运行它时,如果我在应用程序中调用它,它会删除所有数据。
这是创建查询的函数:
public void RemoveElement(string Language, long OrderID) {
ConnectionString = CreateConnectionstring();
string Query = @"DELETE FROM [dbo].[Orders] WHERE ([OrderID]=OrderID);";
using (Command = new SqlCommand(Query, ConnectionString)){
Command.Parameters.AddWithValue("@OrderID", OrderID);
SqlExecution(Language, ConnectionString, Command);
}
}
Run Code Online (Sandbox Code Playgroud)
这是执行查询的函数:
private void SqlExecution(string Language,SqlConnection ConnectionString, SqlCommand Command){
try {
ConnectionString.Open();
Command.ExecuteNonQuery();
Command.Dispose();
// ...
}
//after this line they are message alerts to inform user about success or failure of the action
}
Run Code Online (Sandbox Code Playgroud)
OrderID 是 PK,查询按原样执行(没有错误或错误数据),但它不会只删除选定的订单,而是删除所有内容(我使用了 quickwatch 和调试器,并显示只有选定的订单 ID 被传递。
提前致谢!