Hello
thanks for your reply. Additional info: at least in my case, it appears the problem only occurs if the events are sent back to VB6 from a separate worker thread in .net. I've found the problem happens after waiting 12 minutes, I haven't tried a smaller idle time. Here is a C# assembly that will cause the problem if accessed from VB6
(note, I've been using "regasm netevents2com.dll /tlb:netevents2com.tlb /codebase" to register this for COM)
-----------------------------------------------------------------------------------------
using System
using System.Runtime.InteropServices
using System.Threading
using System.Windows.Forms
namespace netevents2co
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)
[ComVisibleAttribute(true)
public interface INetTes
int StartThreadedMethod1()
[InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)
[ComVisibleAttribute(true)
public interface INetTestEvents
void TestEvent(string sTxt);
[ComSourceInterfaces(typeof(INetTestEvents))
[ClassInterface(ClassInterfaceType.None)
[ComVisibleAttribute(true)
public class CNetTest : INetTes
public CNetTest(
static CNetTest(
AppDomain currentDomain = AppDomain.CurrentDomain
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler)
private int Method1(
Test("Event from .net")
return(4)
public int StartThreadedMethod1(
if (!Monitor.TryEnter(this,0)
return(1)
if (m_methodThread != null
Monitor.Exit(this)
return((int)1)
ThreadStart method1ThreadDelegate = new ThreadStart(this.ThreadedMethod1)
m_methodThread = new Thread(method1ThreadDelegate)
Monitor.Exit(this)
m_methodThread.Start();
return(0)
private void ThreadedMethod1(
Thread.CurrentThread.ApartmentState = System.Threading.ApartmentState.MTA
Method1()
lock(this
m_methodThread = null
public delegate void TestEventDelegate(string sTxt)
public event TestEventDelegate TestEvent
private void Test(string sTxt
if (TestEvent != null
TestEvent(sTxt)
static private void UnhandledExceptionHandler(object sender, UnhandledExceptionEventArgs args)
tr
Exception e = (Exception)args.ExceptionObject
string sErrorMsg = "An error occurred; please contact the adminstrator with the following information:\n\n"
sErrorMsg = sErrorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace
sErrorMsg += "\n\nThe application will terminate now"
MessageBox.Show(sErrorMsg, "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
catc
tr
MessageBox.Show("Fatal Error: the application will exit now", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
finall
Environment.Exit(5)
Environment.Exit(4)
private Thread m_methodThread
---------------------------------------------------------------------------
here's the sample VB6 code that illustrates the problem. Try pressing the command button a few times to prove it works, then don't press anything for 12 minutes, then press the button again, and you should see the exception
---------------------------------------------------------------------------
Option Explici
Dim WithEvents netTest As netevents2com.CNetTes
Dim INetTest As netevents2com.INetTes
Private Sub Command1_Click(
Dim i As Intege
i =
i = INetTest.StartThreadedMethod
End Su
Private Sub Form_Load(
Set netTest = New netevents2com.CNetTes
Set INetTest = netTes
End Su
Private Sub netTest_TestEvent(ByVal sTxt As String
MsgBox ("received event from COM object: " + sTxt
End Su
--------------------
finally, here's a link to another report I found that sounds similar to the problem I'm seeing
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=4ca801c37654%24957ddcd0%24a501280a%40phx.gbl&rnum=2&prev=/groups%3Fq%3DTargetException%2Bafter%2Bidle%2Btime%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D4ca801c37654%2524957ddcd0%2524a501280a%2540phx.gbl%26rnum%3D