Is it safe to set a property on an object within an async method and then access that property in the caller after the method has been awaited? Or are locks required? My understanding is that the async state machine would ensure this but all examples I've seen use return values from the async method not properties on a passed in parameter or members within the containing class.
class TestClass
{
string Member {get; set; }
public class Parameter
{
public string Property { get; set; }
}
public async Task MethodAsync(Parameter parameter)
{
await Task.Delay(1000);
Member = "Completed";
parameter.Property = "Completed";
}
public async Task RunTestAsync()
{
Member = "Started";
var parameter = new Parameter()
{
Property = "Started"
};
await MethodAsync(parameter);
Console.WriteLine(Member); // Thread safe? Guaranteed to be Completed?
Console.WriteLine(parameter.Property); // Thread safe? Guaranteed to be Completed?
}
}