3

Can someone suggest how I can terminate or go around a CreateObject operation that occasionally takes minutes to finish? Basically I have this code:

Set m_Zeacom = CreateObject("QmCOM.QIntegrate")

that works instantly most of the time, but for some users may take minutes (why - is not important in this context). So what I'd like to do is to set a time limit on CreateObject execution and either kill it or detach my app from it. I've played around with DoEvents trying to proceed with the other code while CreateObject is hanging, but without any luck.

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
  • 1
    The only way you are going to be able to do this in-process is if you have some way of changing the code that gets run when you instantiate "QmCOM.QIntegrate". BigToe's answer is the only one which will allow you to instantiate it asynchronously without having to rewrite the object. – Mark Bertenshaw Jun 22 '14 at 22:21
  • IIRC there are timeout options exposed by the distributed transaction coordinator if you run a COM server under COM+ (or component services/transaction server or whatever they call it these days) – Alex K. Jun 23 '14 at 13:12

1 Answers1

4

Another option is to have the CreateObject call in an ActiveX EXE which runs outside of your process.

  • So say the we call that ActiveX EXE OutOfBounds.Factory.
  • You implement a Callback interface in your class something like IListener.Callback which accepts an object as part of the callback.
  • You create an OutOfBounds.Factory class.
  • The out of bounds factory class has a method call GetQmCom which accepts an IListener callback.
  • The GetQmCom methods in your ActiveX EXE returns immediately, but in the background (say in a timer event) it creates the object, once the object is created it calls the callback passing in the object created.
  • Disadvantage of that is the other process owns the object so you end up with cross process calling when you use it in you process. If you don't call it much, you can probably get away with that.
  • Disadvantage, all your code would need to deal with not having an actual instance of the object, as it's non deterministic as to when it arrives from the ActiveX EXE (but you probably need to do that anyway if you are willing to skip it or time out).
  • Advantage, using an ActiveX EXE (dependning on what way you code it) you can cache/share instances as required.

I don't have VB6 any more otherwise I would knock up an example for you.

You may find this MS link about ActiveX EXE's useful http://msdn.microsoft.com/en-us/library/aa262306(v=vs.60).aspx

Bigtoe
  • 3,372
  • 1
  • 31
  • 47
  • Interesting idea. I don't really want to create another exe just for that purpose, though. Might use if nothing else comes up. Thanks – user3042375 Jun 20 '14 at 16:58