我下载了所有邮件并检查了它们的附件。他们正在填充 RAM。我在线程中被称为该代码。我尝试使用 client.Dispose() 和 GC.Collect() 但没有帮助:((
using (var client = new ImapClient(hostname, true))
{
if (client.Connect( /* optional, use parameters here */ ))
{
// connection successful
if (client.Login(login, pass))
{
// login successful
FolderCollection folders = client.Folders;
int i = 0;
foreach (Folder myfolder in folders)
{
var messages = client.Folders[i].Search("ALL");
i++;
foreach (var message in messages)
{
var attachments = message.Attachments;
if (attachments.Count() > 0)
if (!Directory.Exists(folder + @"\" + login))
{
DirectoryInfo di = Directory.CreateDirectory(folder + @"\" + login);// Try to create the directory.
}
foreach (var attachment in attachments)
{
attachment.Download();
attachment.Save(folder + @"\" + login);
}
}
GC.Collect();
}
}
}
client.Disconnect();
client.Dispose();
}