【发布时间】:2020-03-16 16:29:58
【问题描述】:
加载我的数据
Uri.TryCreate(realmPath, UriKind.Relative, out var outPathUri);
RealmConfigurationBase configuration = new FullSyncConfiguration(outPathUri, _currentUser, _realmFile)
{
ObjectClasses = typesInSelectedRealm,
SchemaVersion = 1
};
_realmInstance = Realm.GetInstance(configuration);
if(_realmInstance != null) _realmInstance.RealmChanged += LoadDataOnChange;
尝试从 USB 驱动器复制相同格式的 .realm 文件
if(_realmInstance != null)
{
_realmInstance.RealmChanged -= LoadDataOnChange; // figure it's good to clear all external references to Realm object
_realmInstance.Dispose();
GC.Collect();
Thread.Sleep(1000); // both of these are me trying to just make darn sure that everything is cleaned up and has had enough time to do so
Realm.DeleteRealm(_realmInstance.Config); // error
}
抛出的错误:The process cannot access the file '...\test.realm' because it is being used by another process.
我已经看到this thread,这是我发现的最接近我的问题和可能的解决方案,虽然它是针对 IOS 的,所以我不确定有多少适用于我的情况。
【问题讨论】:
-
适用。如果您连接到 Realm - 您已连接并且无法删除。您必须在任何初始连接之前将其删除。