Hello,
I have only one continuous replicator. How to close database on application close without crash?
My code:
if (App.CBReplicator != null)
{
App.CBReplicator.Stop();
App.CBReplicator.Dispose();
App.CBReplicator = null;
App.CBDatabase.Close();
}
By “crash” do you mean “exception” because there is a distinct lack of detail here.
One thing to point out is that you need to wait for the replicator to stop before you try to close the database. Calling Stop()
is not a synchronous function. The status of the replicator must be changed to Stopped
first (you can track this via the StatusChanged
callback)
Hi @Arnoldas_Zukauskas ,
As borden said you have to make sure replicator is actually stopped, otherwise it throws an error when you close database. There are few ways to check with APIs provided
You can do status activity check is idle
Once you add App.CBReplicator.Stop()
Check for status
App.CBReplicator.status.activity . If it is idle, then you can close the database
App.CBReplicator.Stop();
if App.CBReplicator.status.activity == “idle”
App.CBDatabase.Close();
You can also do check for status by progress total == progress completed (App.CBReplicator.status.progress.completed == App.CBReplicator.status.progress.total)
“stopped”, not “idle”. “idle” is when the replicator is still running but not currently processing.
Thank you for the answer. It helped.
I did:
if (App.CBReplicator != null)
{
App.CBReplicator.Stop();
var status = App.CBReplicator.Status.Activity;
while(status != Couchbase.Lite.Sync.ReplicatorActivityLevel.Stopped)
{
status = App.CBReplicator.Status.Activity;
}
App.CBReplicator.Dispose();
App.CBReplicator = null;
App.CBDatabase.Close();
App.CBDatabase.Dispose();
App.CBDatabase = null;
}
You should improve documentation and examples.
I filed a documentation ticket for it, but you can also do the same in the future if you find the documentation lacking by pressing the “Feedback?” button in the bottom right hand side of any docs page.
Thanks. Agree. I have one more open question regarding tombstones deletion and purging. Functionality does not work as documented. I can delete documents vianq1 but cannot purge already deleted document. My auto compaction setting should remove automatically every 3 days. But this does not work. Manual purge does not work also. I am receiving an error. More info: How to remove all sync information from bucet. Purge does not work ! Sync issues!