@@ -210,7 +210,6 @@ await Task.Run(() =>
210
210
}
211
211
Task . WaitAll ( tasks . ToArray ( ) ) ;
212
212
InitNetwork ( ) ;
213
- Downloads . Clear ( ) ;
214
213
RecoverDownloads ( ) . Wait ( ) ;
215
214
} ) ;
216
215
Running = true ;
@@ -494,7 +493,7 @@ private void TryScheduleAttachmentDownload(SignalAttachment attachment)
494
493
// this is the recommended way to call CreateDownload
495
494
// see https://docs.microsoft.com/en-us/uwp/api/windows.networking.backgroundtransfer.backgrounddownloader#Methods
496
495
DownloadOperation download = downloader . CreateDownload ( new Uri ( RetrieveAttachmentUrl ( attachmentPointer ) ) , tmpDownload ) ;
497
- attachment . Guid = "" + download . Guid ;
496
+ attachment . Guid = download . Guid . ToString ( ) ;
498
497
SignalDBContext . UpdateAttachmentGuid ( attachment ) ;
499
498
Downloads . Add ( attachment . Id , download ) ;
500
499
Task . Run ( async ( ) =>
@@ -559,13 +558,20 @@ private async Task RecoverDownloads()
559
558
SignalAttachment attachment = SignalDBContext . GetAttachmentByGuidNameLocked ( download . Guid . ToString ( ) ) ;
560
559
if ( attachment != null )
561
560
{
562
- Downloads . Add ( attachment . Id , download ) ;
563
- var t = Task . Run ( async ( ) =>
561
+ if ( ! Downloads . ContainsKey ( attachment . Id ) )
564
562
{
565
- Logger . LogInformation ( "Attaching to download {0} ({1})" , attachment . Id , download . Guid ) ;
566
- await download . AttachAsync ( ) ;
567
- await HandleSuccessfullDownload ( attachment , download . ResultFile , download ) ;
568
- } ) ;
563
+ Logger . LogInformation ( "Creating attach task for attachment {0} ({1})" , attachment . Id , download . Guid ) ;
564
+ Downloads . Add ( attachment . Id , download ) ;
565
+ var t = Task . Run ( async ( ) =>
566
+ {
567
+ await download . AttachAsync ( ) ;
568
+ await HandleSuccessfullDownload ( attachment , download . ResultFile , download ) ;
569
+ } ) ;
570
+ }
571
+ else
572
+ {
573
+ Logger . LogInformation ( "Attachment {0} ({1}) already has a running task" , attachment . Id , download . Guid ) ;
574
+ }
569
575
}
570
576
else
571
577
{
0 commit comments