As others have noted, the compiler error is in your variable declaration (Task
does not have a Result
property):
var nextElement = dir.GetValue(i++).ToString();
var buffering = Task.Run(() => imageHashing(nextElement));
bitmapBuffer = buffering.Result;
However, this code is also problematic. In particular, it makes no sense to kick work off to a background thread if you're just going to block the current thread until it completes. You may as well just call the method directly:
var nextElement = dir.GetValue(i++).ToString();
bitmapBuffer = imageHashing(nextElement);
Or, if you are on a UI thread and do not want to block the UI, then use await
instead of Result
:
var nextElement = dir.GetValue(i++).ToString();
bitmapBuffer = await Task.Run(() => imageHashing(nextElement));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…