I have a problem that for loop to add item
I see aws table just add one row after finished
I try so many way but they doesn't work
class Program : Base
{
static void Main(string[] args)
{
stock_group stock_group = new stock_group();
stock_group.default_insert();
}
}
public async Task<bool> default_insert()
{
List<tb_stock_group> data = JsonConvert.DeserializeObject<tb_stock_group>>(@"
[{""id"":1,""name"":""水泥工業""},
{""id"":2,""name"":""食品工業""},
{""id"":3,""name"":""塑膠工業""}]
");
for (int i = 0; i < data.Count; i++)
{
var response = await SaveToDynamoDB(data[i]);
Console.WriteLine(response);
}
Console.WriteLine("success!");
return false;
}
public async Task<T> SaveToDynamoDB<T>(T obj) where T :class
{
DynamoDBContext context = new DynamoDBContext(Get_Client());
await context.SaveAsync(obj);
var response = await context.LoadAsync<T>(obj);
return response;
}
In all likelihood, the program is exiting before most of the calls to DynamoDB happen. This is because you are making a call to an async
function from code that is not async
. If you change the code in static Main
to the following it should work:
class Program : Base
{
static void Main(string[] args)
{
stock_group stock_group = new stock_group();
stock_group.default_insert().Wait();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.