In this question Get the id of inserted row using C#, some comments mention that last_insert_id/LastInsertedId is not thread safe, then what is the thread safe way? Is transaction like bellow enough?
MySqlTransaction tr = mysqlcon.BeginTransaction();
MySqlCommand cmd=new MySqlCommand("insert ...", mysqlcon, tr);
cmd.ExecuteNonQuery();
long id = cmd.LastInsertedId;
tr.Commit();