C# .net core 3.1
這段程式碼實際上有幾個Save是可以成功的?
var obj = LCObject.Create("Test");
obj["count"] = 0;
await obj.Save();
async Task Save(int count)
{
var obj2 = LCObject.CreateWithoutData("Test", obj.ObjectId);
obj2["count"] = count;
var condition = new LCQuery<LCObject>("Test");
condition.WhereEqualTo("count", 0);
await obj2.Save(true, condition);
// 有幾個能成功Save ??
}
var tasks = new List<Task>();
for (int i = 0; i < 5; i++)
{
tasks.Add(Save(i + 1));
}
await Task.WhenAll(tasks);
大量同時對同一物件做有條件的Save時 這樣的寫法能保證只有一個Save會成功嗎?