我在這裏只是嘗試從服務器使用IMAP與ComponentPro .net組件(Asynchronous Task-Based Approach)下載「INBOX」中的電子郵件,但每次嘗試異步方法時都會引發錯誤。異步操作此時無法啓動
我已經使用IMAP以同步方式下載了Inbox電子郵件,但這需要將近3-4分鐘才能下載至少80多封電子郵件,所以我想嘗試異步方法對此有任何建議,因爲我嘗試的是第一種異步方法時間。
錯誤:
An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle.
控制器代碼:
public ActionResult ImportEmailDemo()
{
var sImportedEmails = ARepository.ImportEmailForDemo();
return null;
}
庫代碼:
public async Task<string> ImportEmailForDemo()
{
//Async
// Create a new instance of the Imap class.
Imap client1 = new Imap();
// Connect to the server.
client1.Connect("Server Address");
// Or you can specify the IMAP port with
// client.Connect("myserver", 143);
// Login to the server.
client1.Authenticate("EmailID", "Password");
// Select 'INBOX' mailbox.
client1.Select("INBOX");
// Download a mail message with sequence number 1.
ComponentPro.Net.Mail.MailMessage msg = await client1.DownloadMailMessageAsync(1);
// ...
Console.WriteLine("Message downloaded successfully.");
Console.WriteLine("Message ID: {0}, Subject: {1}", msg.MessageIdentifier, msg.Subject);
// Disconnect.
client1.Disconnect();
return null;
}
我用不同的方式來解決的錯誤期待在互聯網,但沒有什麼工作,我試過, 誰能幫我嗎。 乾杯!
問題在於你的調用方法。請將其添加到您的問題。 – Sefe
好吧,我已經添加了我調用它的控制器代碼。 – pavan