Revision 8d38a269 trunk/Pithos.Network/Signature.cs

b/trunk/Pithos.Network/Signature.cs
92 92
            if (fileInfo is DirectoryInfo || !fileInfo.Exists)
93 93
                return TreeHash.Empty;
94 94

  
95
            return CalculateTreeHashAsync(fileInfo, blockSize, algorithm, 1, token, progress);
95
            return TaskEx.Run(async ()=>await CalculateTreeHashAsync(fileInfo, blockSize, algorithm, 1, token, progress)).Result;
96 96
        }
97 97

  
98 98
        /// <summary>
......
113 113
            Contract.EndContractBlock();
114 114

  
115 115
            var info = FileInfoExtensions.FromPath(filePath);
116
            var hash=CalculateTreeHashAsync(info, blockSize, algorithm, 1,token,progress);
116
            var hash=TaskEx.Run(async ()=>await CalculateTreeHashAsync(info, blockSize, algorithm, 1,token,progress).ConfigureAwait(false)).Result;
117 117
            return hash;
118 118
        }
119 119
        
120 120

  
121
        public static TreeHash CalculateTreeHashAsync(string filePath, int blockSize, string algorithm, byte parallelism,CancellationToken token,IProgress<HashProgress> progress )
121
        public static Task<TreeHash> CalculateTreeHashAsync(string filePath, int blockSize, string algorithm, byte parallelism,CancellationToken token,IProgress<HashProgress> progress )
122 122
        {
123 123
            if (filePath== null)
124 124
                throw new ArgumentNullException("filePath");
......
134 134

  
135 135

  
136 136

  
137
        public static TreeHash CalculateTreeHashAsync(FileSystemInfo info, int blockSize,string algorithm, int parallelism,CancellationToken token,IProgress<HashProgress> progress )
137
        public static async Task<TreeHash> CalculateTreeHashAsync(FileSystemInfo info, int blockSize,string algorithm, int parallelism,CancellationToken token,IProgress<HashProgress> progress )
138 138
        {
139 139
            if (info==null)
140 140
                throw new ArgumentNullException("info");
......
168 168
                //var md5 = new MD5BlockCalculator();
169 169
                //Action<long, byte[], int> postAction = md5.PostBlock;
170 170
                //Calculate the blocks asyncrhonously
171
                var hashes = BlockHashAlgorithms.CalculateBlockHashesInPlacePFor(stream, blockSize, algorithm, parallelism,token, progress).Result;
171
                var hashes = await BlockHashAlgorithms.CalculateBlockHashesInPlacePFor(stream, blockSize, algorithm, parallelism,token, progress).ConfigureAwait(false);
172 172
                //var hashes = BlockHashAlgorithms.CalculateBlockHashesInPlacePFor(stream, blockSize, algorithm, parallelism, postAction, token, progress).Result; 
173 173

  
174 174
                //And then proceed with creating and returning a TreeHash

Also available in: Unified diff