public async Task <int> LoadByPortionsAsync() { data = new byte[dataLenght]; int CurrentPercent = 0; double p; while (position < dataLenght) { p = position * 100.0 / dataLenght; chunkSize = Math.Min(chunkSize, dataLenght - position); await JsFastDataExchanger.GetBinaryDataByPortions(this); position += chunkSize; if (CurrentPercent != (int)p) { CurrentPercent = (int)p; progressInfo = ".net loaded " + (int)p + " of 100%"; OnDataRead?.Invoke(CurrentPercent); } } progressInfo = ".net loaded 100 of 100%"; OnDataRead?.Invoke(100); JsFastDataExchanger.DeleteGlobalVariable(variableName); OnFinish?.Invoke(); return(1); }