これは機能しますが、Resharper はコメント行に「 Discarded Closure へのアクセス」と言っています
using (var db = new SQLiteConnection(SQLitePath))
            {
                db.CreateTable<Locations>();
                db.RunInTransaction(() =>
                {
                    db.Insert(new Locations // Resharper: "Access to disposed closure" ???
                    {
                        PersonId = personId,
                        Latitude = latitude,
                        Longitude = longitude,
                        SentTimeUTC = sentTimeUTC,
                        ReceivedTimeLocal = receivedTimeLocal,
                        CivicAddress = civicAddress
                    });
                });
            }
この代替アプローチも機能しますが、Resharper からの同じフィンガーワグを使用します。
    var db = new SQLiteConnection(SQLitePath);
    {
        db.CreateTable<Locations>();
        db.RunInTransaction(() =>
        {
            db.Insert(new Locations // this works, although Resharper warns: "Access to disposed closure" ???
               {
                   PersonId = personId,
                      Latitude = latitude,
                      Longitude = longitude,
                      SentTimeUTC = sentTimeUTC,
                      ReceivedTimeLocal = ReceivedTimeLocal,
                      CivicAddress = civicAddress
               });
        });
    }
    db.Dispose();
どちらも機能するので、あまり問題にはならないと思いますが、一方の方法がもう一方の方法よりも優れていますか? Resharper を緩和し、それでも仕事を成し遂げる方法はありますか?
アップデート
Donal の発言は理にかなっているように見えましたが、このリファクタリングされたコードで、xaction 内の Insert ステートメントで Resharper の「潜在的なコード品質の問題」という警告がまだ表示されます。
public void InsertLocationRecord(string personId, double latitude, double longitude,
    DateTime sentTimeUTC, DateTime receivedTimeLocal, string civicAddress) 
{
    Locations locs = new Locations { PersonId = personId,
                                     Latitude = latitude,
                                     Longitude = longitude,
                                     SentTimeUTC = sentTimeUTC,
                                     ReceivedTimeLocal = receivedTimeLocal,
                                     CivicAddress = civicAddress
                                   };
    using (var db = new SQLiteConnection(SQLitePath))
    {
        db.CreateTable<Locations>();
        db.RunInTransaction(() =>
                                {
                                    db.Insert(locs); // Still get, "Access to disposed closure" on this line.
                                });
    }
}
多分私は間違った方法で問題をリファクタリングしていますか? これは前の方法とあまり変わらないと思います。locs インスタンスが確実に破棄されるようにするにはどうすればよいですか? それとも、それはここでの問題ではありませんか?