[f-spot] Make sure db events always happen on main thread.



commit 23ed5b0fb54cf672448236d8f11162938ea4e33d
Author: Ruben Vermeersch <ruben savanne be>
Date:   Wed Jun 30 10:14:47 2010 +0200

    Make sure db events always happen on main thread.
    
    Can solve quite a few crashers.

 src/Db.cs |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/src/Db.cs b/src/Db.cs
index b27b38f..e6097e4 100644
--- a/src/Db.cs
+++ b/src/Db.cs
@@ -61,8 +61,7 @@ public abstract class DbStore<T> where T : DbItem {
 
 	protected void EmitAdded (T [] items)
 	{
-		if (ItemsAdded != null)
-			ItemsAdded (this, new DbItemEventArgs<T> (items));
+		EmitEvent (ItemsAdded, new DbItemEventArgs<T> (items));
 	}
 
 	protected void EmitChanged (T item)
@@ -77,8 +76,7 @@ public abstract class DbStore<T> where T : DbItem {
 
 	protected void EmitChanged (T [] items, DbItemEventArgs<T> args)
 	{
-		if (ItemsChanged != null)
-			ItemsChanged (this, args);
+		EmitEvent (ItemsChanged, args);
 	}
 
 	protected void EmitRemoved (T item)
@@ -88,8 +86,17 @@ public abstract class DbStore<T> where T : DbItem {
 
 	protected void EmitRemoved (T [] items)
 	{
-		if (ItemsRemoved != null)
-			ItemsRemoved (this, new DbItemEventArgs<T> (items));
+		EmitEvent (ItemsRemoved, new DbItemEventArgs<T> (items));
+	}
+
+	private void EmitEvent (EventHandler<DbItemEventArgs<T>> evnt, DbItemEventArgs<T> args)
+	{
+		if (evnt == null) // No subscribers.
+			return;
+
+		ThreadAssist.ProxyToMain (() => {
+			evnt (this, args);
+		});
 	}
 
 	public bool CacheEmpty {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]