F#: only do one action once for the first event, without mutability/locking?
问题 I have this code that downloads a file and tells me in the console how big is the file: use webClient = new WebClient() let lockObj = new Object() let mutable firstProgressEvent = true let onProgress (progressEventArgs: DownloadProgressChangedEventArgs) = lock lockObj (fun _-> if (firstProgressEvent) then let totalSizeInMB = progressEventArgs.TotalBytesToReceive / 1000000L Console.WriteLine ("Starting download of {0}MB...", totalSizeInMB) firstProgressEvent <- false ) webClient