I have a problem with my tasks. When I try to recive returned variable from my task I can\'t use a .Result property to get it. Here is my code:
var nextEleme
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));
You should use Task<bool[]>
for the buffering variable. Not specifying the type means that the operation is not expected to return any result.
You should declare buffering variable as Task<byte[]> buffering = Task<byte[]>.Run(() => imageHashing(nextElement));