问题
If I have a static method to convert one object to another object, is this method thread safe in C#?
public static AnotherDataClass Convert(MyDataClass target)
{
AnotherDataClass val = new AnotherDataClass();
// read infomration from target
// put information into val;
return val;
}
Just want to make the question more clear....
when invoke the convert method.... we can assume that target is not going be be modified. since the Convert method only interested in the "attrubite" of target
回答1:
No, it is not.
"A method would be thread safe if it would b accessing data that won't be accessible to any other thread" If this definition is correct then the method is not thread safe
Reason
MyDataClass seems reference type to me so there is a chance that multiple threads might be changing the target variable
来源:https://stackoverflow.com/questions/8370636/is-static-method-thread-safe