Index: /trunk/src/VBox/Main/ConsoleImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 30590)
+++ /trunk/src/VBox/Main/ConsoleImpl.cpp	(revision 30591)
@@ -4976,6 +4976,6 @@
         }
         evDesc.init(mEventSource, VBoxEventType_OnCanShowWindow);
-        BOOL fDelivered = evDesc.fire(10000); /* Wait up to 10 secs for delivery */
-        Assert(fDelivered);
+        BOOL fDelivered = evDesc.fire(5000); /* Wait up to 5 secs for delivery */
+        //Assert(fDelivered);
         if (fDelivered)
         {
@@ -4997,8 +4997,5 @@
         }
         else
-        {
-            Assert(FALSE);
             *aCanShow = TRUE;
-        }
     }
     else
@@ -5027,19 +5024,17 @@
             ++it;
         }
-#if 1
         evDesc.init(mEventSource, VBoxEventType_OnShowWindow, UINT64_C(0));
-        ComPtr<IEvent> aEvent;
-        evDesc.getEvent(aEvent.asOutParam());
-        ComPtr<IShowWindowEvent> aShowEvent = aEvent;
-
-        BOOL fDelivered = evDesc.fire(10000); /* Wait up to 10 secs for delivery */
-        Assert(fDelivered);
+        BOOL fDelivered = evDesc.fire(5000); /* Wait up to 5 secs for delivery */
+        //Assert(fDelivered);
         if (fDelivered)
         {
+            ComPtr<IEvent> aEvent;
+            evDesc.getEvent(aEvent.asOutParam());
+            ComPtr<IShowWindowEvent> aShowEvent = aEvent;
             ULONG64 aEvWinId = 0;
             if (aShowEvent)
             {
                 aShowEvent->COMGETTER(WinId)(&aEvWinId);
-                if (aEvWinId != 0)
+                if ((aEvWinId != 0) && (*aWinId == 0))
                     *aWinId = aEvWinId;
             }
@@ -5047,7 +5042,4 @@
                 Assert(FALSE);
         }
-        else
-            Assert(FALSE);
- #endif
     }
 
Index: /trunk/src/VBox/Main/EventImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/EventImpl.cpp	(revision 30590)
+++ /trunk/src/VBox/Main/EventImpl.cpp	(revision 30591)
@@ -357,4 +357,6 @@
         return mActive;
     }
+
+    friend class EventSource;
 };
 
@@ -736,5 +738,13 @@
              */
             cbRc = record.obj()->process(aEvent, aWaitable, pit, alock);
-            // what to do with cbRc?
+
+            if (FAILED_DEAD_INTERFACE(cbRc))
+            {
+                AutoWriteLock awlock(this COMMA_LOCKVAL_SRC_POS);
+                Listeners::iterator lit = m->mListeners.find(record.obj()->mListener);
+                if (lit != m->mListeners.end())
+                    m->mListeners.erase(lit);
+            }
+            // anything else to do with cbRc?
         }
     } while (0);
Index: /trunk/src/VBox/Main/VirtualBoxImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 30590)
+++ /trunk/src/VBox/Main/VirtualBoxImpl.cpp	(revision 30591)
@@ -2752,6 +2752,6 @@
     VBoxEventDesc evDesc;
     evDesc.init(m->pEventSource, VBoxEventType_OnExtraDataCanChange, id.raw(), aKey, aValue);
-    BOOL fDelivered = evDesc.fire(10000); /* Wait up to 10 secs for delivery */
-    Assert(fDelivered);
+    BOOL fDelivered = evDesc.fire(3000); /* Wait up to 3 secs for delivery */
+    //Assert(fDelivered);
     if (fDelivered)
     {
Index: /trunk/src/VBox/Main/glue/tests/TestVBox.java
===================================================================
--- /trunk/src/VBox/Main/glue/tests/TestVBox.java	(revision 30590)
+++ /trunk/src/VBox/Main/glue/tests/TestVBox.java	(revision 30591)
@@ -207,7 +207,23 @@
     }
 
-    static void testEvents(VirtualBoxManager mgr, IEventSource es)
-    {
-        IEventListener listener = es.createListener();
+    static class EventHandler
+    {
+        EventHandler() {}
+        public void handleEvent(IEvent ev)
+        {
+            try {
+                processEvent(ev);
+            } catch (Throwable t) {
+                t.printStackTrace();
+            }
+        }
+    }
+
+    static void testEvents(VirtualBoxManager mgr, IEventSource es, boolean active)
+    {
+        // active mode for Java doesn't fully work yet, and using passive
+        // is more portable (the only mode for MSCOM and WS) and thus generally 
+        // recommended
+        IEventListener listener = active ? mgr.createListener(new EventHandler()) : es.createListener();
 
         es.registerListener(listener, Arrays.asList(VBoxEventType.Any), false);
@@ -216,10 +232,17 @@
             for (int i=0; i<100; i++)
             {
-                IEvent ev = es.getEvent(listener, 1000);
                 System.out.print(".");
-                if (ev != null)
+                if (active)
                 {
-                    processEvent(ev);
-                    es.eventProcessed(listener, ev);
+                    mgr.waitForEvents(500);
+                }
+                else
+                {
+                    IEvent ev = es.getEvent(listener, 1000);
+                    if (ev != null)
+                    {
+                        processEvent(ev);
+                        es.eventProcessed(listener, ev);
+                    }
                 }
             }
@@ -263,5 +286,5 @@
             testStart(mgr, vbox);
             //testCallbacks(mgr, vbox);
-            testEvents(mgr, vbox.getEventSource());
+            testEvents(mgr, vbox.getEventSource(), false);
 
             System.out.println("done, press Enter...");
