Hi All,

I have a .NET (managed C++) class called Foo that raises a managed event.
I'm trying to catch the managed event in a VB6 app.

My VB6 app has 2 Withevents variables referencing the same Foo instance.
Depending on the order I connect and disconnect the Withevents variables to
the Foo instance, determines whether my app works fine or hangs with the
CPU load at 100%. (disconnecting in the reverse order of the connections
makes the app work fine)

Attaching the debugger to the hung process shows the processor is bouncing
between VB6 EVENT_SINK code and the runtime.

Any light that can be shed on this is greatly appreciated.

Thanks in advance,
Cy Marrion

---------------------------------------------------
Here's the managed C++ code:
---------------------------------------------------

  public __delegate void ChangedDelegate();

  [InterfaceTypeAttribute(ComInterfaceType::InterfaceIsIDispatch )]
  public __gc __interface IFooEvent
  {
    [DispIdAttribute(88)]
    void Changed();
  };

  [ComSourceInterfacesAttribute(__typeof(IFooEvent))]
  [event_source(managed)]
  public __gc class Foo
  {
  public:
    void Bar()
    {
      __raise Changed();
    }
    __event ChangedDelegate* Changed;
  };


---------------------------------------------------
Here's the VB6 app code:
---------------------------------------------------

Dim WithEvents f As Foo
Dim WithEvents f2 As Foo

Private Sub Command2_Click()
  ' This sequence is OK
  Set f = New Foo
  Set f = Nothing

  ' This sequence is OK
  Set f = New Foo
  Set f2 = New Foo
  Set f = Nothing
  Set f2 = Nothing

  ' This sequence is OK
  Set f = New Foo
  Set f2 = f
  Set f2 = Nothing
  Set f = Nothing

  ' This sequence is the problem
  Set f = New Foo
  Set f2 = f
  Set f = Nothing      ' causes the process to hang, CPU load = 100%
  Set f2 = Nothing
End Sub

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to