' "doc" object already exists as an XmlDocument
SyncLock doc
Dim newsub As XmlElement = doc.CreateElement("submission")
End SyncLock
' use "newsub" here without synchronization
SyncLock doc
doc.Item("submissions").AppendChild(newsub)
End SyncLock
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
这意味着,如图所示,在追加孩子时你需要同步.
As a followup to this question, would I be better off just synchronizing the entire building of the “newsub” object? The reason I think doing it like above is better is for performance, but I am not by any means an expert in whether I am actually making a meaningful impact on performance, or just complicating things.
' "doc" object already exists as an XmlDocument
SyncLock doc
Dim newsub As XmlElement = doc.CreateElement("submission")
End SyncLock
' use "newsub" here without synchronization
SyncLock doc
doc.Item("submissions").AppendChild(newsub)
End SyncLock
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
这意味着,如图所示,在追加孩子时你需要同步.
As a followup to this question, would I be better off just synchronizing the entire building of the “newsub” object? The reason I think doing it like above is better is for performance, but I am not by any means an expert in whether I am actually making a meaningful impact on performance, or just complicating things.