2017-04-09 13 views
0

몇 개의 전자 메일 계정에서 첨부 파일을 다운로드하고 있습니다. 나는 각 계정 (거울)에 예를 들면 300 개의 첨부 파일을 가지고있다. 나는 하나 개의 계정에서 첨부 파일을 다운로드 할 때, 나는 내 프로그램 로그에 오류가 발생합니다 :MailKit을 사용하여 많은 첨부 파일을 다운로드하는 동안 System.OutOfMemoryException

... 
09.04.2017 16:10:07: Download attachment nr 108 from task Movie.avi 
09.04.2017 16:10:59: Download attachment nr 109 from task Movie.avi 
09.04.2017 16:11:26: Download attachment nr 110 from task Movie.avi 
09.04.2017 16:12:07: Download attachment nr 111 from task Movie.avi 
09.04.2017 16:12:34: Download attachment nr 112 from task Movie.avi 
09.04.2017 16:13:07: Download attachment nr 113 from task Movie.avi 
09.04.2017 16:13:55: Download attachment nr 114 from task Movie.avi 
09.04.2017 16:14:03: System.OutOfMemoryException: Zgłoszono wyjątek typu 'System.OutOfMemoryException'. 
    w MimeKit.IO.MemoryBlockStream.Write(Byte[] buffer, Int32 offset, Int32 count) 
    w MailKit.Net.Imap.ImapFolder.FetchStream(ImapEngine engine, ImapCommand ic, Int32 index) 
    w MailKit.Net.Imap.ImapEngine.ProcessUntaggedResponse(CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapCommand.Step() 
    w MailKit.Net.Imap.ImapEngine.Iterate() 
    w MailKit.Net.Imap.ImapEngine.Wait(ImapCommand ic) 
    w MailKit.Net.Imap.ImapFolder.GetMessage(UniqueId uid, CancellationToken cancellationToken, ITransferProgress progress) 
    w MailExchange.Form1.makeDownload(String nazwa) w c:\Users\DamianOS.MP5\Documents\mailexchange\MailExchange\Form1.cs:wiersz 1086 
09.04.2017 16:14:47: System.OutOfMemoryException: Zgłoszono wyjątek typu 'System.OutOfMemoryException'. 
    w MailKit.Net.Imap.ImapStream.ReadQuotedStringToken(Byte* inbuf, CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapStream.ReadToken(String specials, CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapStream.ReadToken(CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapUtils.ParseEnvelopeAddress(ImapEngine engine, String format, CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapUtils.ParseEnvelopeAddressList(InternetAddressList list, ImapEngine engine, String format, CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapUtils.ParseEnvelope(ImapEngine engine, CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapFolder.FetchSummaryItems(ImapEngine engine, ImapCommand ic, Int32 index) 
    w MailKit.Net.Imap.ImapEngine.ProcessUntaggedResponse(CancellationToken cancellationToken) 
    w MailKit.Net.Imap.ImapCommand.Step() 
    w MailKit.Net.Imap.ImapEngine.Iterate() 
    w MailKit.Net.Imap.ImapEngine.Wait(ImapCommand ic) 
    w MailKit.Net.Imap.ImapFolder.Fetch(Int32 min, Int32 max, MessageSummaryItems items, CancellationToken cancellationToken) 
    w MailExchange.Form1.makeDownload(String nazwa) w c:\Users\DamianOS.MP5\Documents\mailexchange\MailExchange\Form1.cs:wiersz 1041 
09.04.2017 16:15:04: System.OutOfMemoryException: Zgłoszono wyjątek typu 'System.OutOfMemoryException'. 
    w System.Text.StringBuilder..ctor(String value, Int32 startIndex, Int32 length, Int32 capacity) 
    w MimeKit.Utils.ParseUtils.TryParseDotAtom(Byte[] text, Int32& index, Int32 endIndex, Byte[] sentinels, Boolean throwOnError, String tokenType, String& dotatom) 
    w MimeKit.InternetAddress.TryParseAddrspec(Byte[] text, Int32& index, Int32 endIndex, Byte[] sentinels, Boolean throwOnError, String& addrspec) 
    w MimeKit.InternetAddress.TryParseMailbox(ParserOptions options, Byte[] text, Int32 startIndex, Int32& index, Int32 endIndex, String name, Int32 codepage, Boolean throwOnError, InternetAddress& address) 
    w MimeKit.InternetAddress.TryParse(ParserOptions options, Byte[] text, Int32& index, Int32 endIndex, AddressParserFlags flags, InternetAddress& address) 
    w MimeKit.InternetAddressList.TryParse(ParserOptions options, Byte[] text, Int32& index, Int32 endIndex, Boolean isGroup, Boolean throwOnError, List`1& addresses) 
    w MimeKit.MimeMessage.AddAddresses(Header header, InternetAddressList list) 
    w MimeKit.MimeMessage.HeadersChanged(Object o, HeaderListChangedEventArgs e) 
    w MimeKit.HeaderList.OnChanged(Header header, HeaderListChangedAction action) 
    w MimeKit.HeaderList.Add(Header header) 
    w MimeKit.MimeMessage..ctor(ParserOptions options, IEnumerable`1 headers) 
    w MimeKit.MimeParser.ParseMessage(Byte* inbuf) 
    w MimeKit.MimeParser.ParseMessage(CancellationToken cancellationToken) 
    w MailKit.Net.Pop3.Pop3Client.DownloadHeaderContext.Parse(Pop3Stream data, CancellationToken cancellationToken) 
    w MailKit.Net.Pop3.Pop3Client.DownloadContext`1.OnDataReceived(Pop3Engine pop3, Pop3Command pc, String text) 
    w MailKit.Net.Pop3.Pop3Engine.ReadResponse(Pop3Command pc) 
    w MailKit.Net.Pop3.Pop3Engine.Iterate() 
    w MailKit.Net.Pop3.Pop3Client.DownloadContext`1.DownloadItem(Int32 seqid, Boolean headersOnly, CancellationToken cancellationToken) 
    w MailKit.Net.Pop3.Pop3Client.GetMessageHeaders(Int32 index, CancellationToken cancellationToken) 
    w MailExchange.Form1.makeDownload(String nazwa) w c:\Users\DamianOS.MP5\Documents\mailexchange\MailExchange\Form1.cs:wiersz 1053 

내가 예를 들어 첫 번째 계정에서 100 개 첨부 파일, 세 번째 계정에서 100 개 번째 계정에서 첨부 파일과 100을 다운로드있을 때, 모든 괜찮아. 하지만 하나의 계정에서 300 개의 첨부 파일을 다운로드하고 싶습니다. 오류가있는 라인 : 파일에서

//1086 line: 
readyMessages.Add(client.Inbox.GetMessage(imapReadySubjects[posortowanaLista[i]].UniqueId, cancellationToken, progress)); 
//1041 line: 
IList<IMessageSummary> allMailList = client.Inbox.Fetch(0, -1, MessageSummaryItems.Envelope | MessageSummaryItems.UniqueId, cancellationToken); 
//1053 line: 
for (int i = 0; i < client2.Count; i++) 
    allMailLists.Add(client2.GetMessageHeaders(i), i); 

전체 코드 : https://bitbucket.org/DamianOS_MP5/mailexchange/src/3af44d3ffa7e61fb40afbcb7d75fefd068b80ff6/MailExchange/Form1.cs?at=master&fileviewer=file-view-default

+0

정보를 더 제공 할 수 있습니까? 귀하의 질문은 명확하지 않습니다. 더 큰 다운로드 배치가 왜 문제 일 수 있으며 어떻게 해결할 수 있는지 묻고 있습니까? 너는 다른 것을 요구하고 있니? – stackuser83

답변

1

문제는 당신이 List의 메시지 수백을 유지하는 것입니다.

해결책 : 그렇게하지 마십시오.

readyMessages 목록이 필요합니까? 가장 최근에 다운로드 한 메시지 인 목록의 마지막 요소에만 액세스합니다.

+0

도움 주셔서 감사합니다. –