Passing raw direct interface pointers around is something i could do in my misspent day of my youth as an ATL programming :-)
I have to say that hand on heart the only way you should do this is to refactor - take the code that is required server side and put it in a separate component marked as ThreadingModel=Both then have the server side call this on an MTA thread and the ActiveX control call it on it's STA thread. Anything else is going to be a hack and hack in COM always lead to alot of pain somewhere down the road Regards Richard Blewett - DevelopMentor > -----Original Message----- > From: Discussion of advanced .NET topics. [mailto:ADVANCED- > [EMAIL PROTECTED] On Behalf Of Pavlo Batsii > Sent: 11 September 2007 14:42 > To: [email protected] > Subject: Re: [ADVANCED-DOTNET] MTA ActiveX - .NET interop > > Richard, > As far as I could see if I 'play nasty with it and pass direct > interface > pointers to other threads', interop does the marshalling automatically > [by > direct interface pointers I mean here C# wrapper reference]. Do you > know of > a way to get to the real interface pointer and create the wrapper > explicitly? > > Concerning thread safety - I am quite sure it is thread safe, lived for > a > while with that component. > > Unfortunately setting 'Both' at registry does not make VS happy, it > still > does the marshalling. > > What I need, is, actually, to run ActiveX method that may block (but > doesn't > deal with UI) in a safe way when it comes to server application, so > each > call to ActiveX method must be made on separate thread. > You may ask why ActiveX , if no UI ? -- well that's because of > 'historical > reasons':) > > > With best regards, > Pavlo Batsii > > ----- Original Message ----- > From: "Richard Blewett" <[EMAIL PROTECTED]> > To: <[email protected]> > Sent: Tuesday, September 11, 2007 4:13 PM > Subject: Re: [ADVANCED-DOTNET] MTA ActiveX - .NET interop > > > > The problem is that an activeX control has to run in an STA and > therefore > > all calls to it will be marshalled on to a single thread (unless you > play > > nasty with it and pass direct interface pointers to other threads). > > > > ActiveX controls are not usually written with multithreading in mind > - how > > do you know its threadsafe? If it truely is thread safe and ok to > call > > from > > an MTA thread you could try setting your threading model to Both and > see > > if > > VS will be happy with that (I've not tested that). > > > > Regards > > > > Richard Blewett - DevelopMentor > > > >> -----Original Message----- > >> From: Discussion of advanced .NET topics. [mailto:ADVANCED- > >> [EMAIL PROTECTED] On Behalf Of Pavlo Batsii > >> Sent: 11 September 2007 13:56 > >> To: [email protected] > >> Subject: Re: [ADVANCED-DOTNET] MTA ActiveX - .NET interop > >> > >> Richard, > >> I have inherited the component and it has some legacy UI which must > be > >> kept > >> (for other native clients). > >> The context in which I would like to run ActiveX code doesn't > involve > >> its > >> UI. > >> I would rather avoid splitting the component, also I would avoid > >> converting > >> it to clean COM component, if that's possible. > >> > >> > >> Thanks & > >> with best regards, > >> Pavlo Batsii > >> > >> > >> ----- Original Message ----- > >> From: "Richard Blewett" <[EMAIL PROTECTED]> > >> To: <[email protected]> > >> Sent: Tuesday, September 11, 2007 3:33 PM > >> Subject: Re: [ADVANCED-DOTNET] MTA ActiveX - .NET interop > >> > >> > >> >I have a couple of questions. > >> > > >> > Is the control a UI element or is it just a component you want to > use > >> for > >> > automation purposes that doesn;t have a UI (say like a timer)? > >> > Have you authored the control or is it a component developed > >> elsewhere? > >> > > >> > Regards > >> > > >> > Richard Blewett - DevelopMentor > >> > > >> >> -----Original Message----- > >> >> From: Discussion of advanced .NET topics. [mailto:ADVANCED- > >> >> [EMAIL PROTECTED] On Behalf Of Pavlo Batsii > >> >> Sent: 11 September 2007 10:53 > >> >> To: [email protected] > >> >> Subject: [ADVANCED-DOTNET] MTA ActiveX - .NET interop > >> >> > >> >> How do can man use ActiveX controls from .NET WinForms app > >> >> so that reference to the IDispatch-implementing object retrieved > >> from > >> >> ActiveX control wrapper wouldn't be necessarily marshalled to the > >> main > >> >> thread and ActiveX code not invoked from STA thread's context? A > >> kind > >> >> of , I would presume, a trivial question that is, only that I > >> couldn't > >> >> get an answer anywhere. > >> >> > >> >> I'll explain: > >> >> > >> >> if one adds the ActiveX on a form, retrieves a pointer to some > >> >> automation object, and tries to call that pointer from other > >> thread's > >> >> context (not from main form, for example), .NET interop marshalls > >> the > >> >> pointer to the main form (by putting a windows message to the > form's > >> >> message queue and processing call at the main form, (in a > >> >> BackgroundWorker fashion?)), so that all calls to ActiveX methods > >> are > >> >> made from the same thread. > >> >> > >> >> I would like to avoid this, because ActiveX component is thread- > safe > >> >> and, actually, such behaviour is not acceptable since ActiveX > method > >> >> may block, and it is invoked from a server application (that is, > >> >> ActiveX method implementation must be called asynchronously, not > one > >> by > >> >> one). > >> >> > >> >> If ActiveX is registered as MTA @ registry then VS designer > throws > >> an > >> >> exception when dragging ActiveX on a form. > >> >> > >> >> Any solutions in case this marshalling cannot be 'disabled'? > >> >> > >> >> Thanks! > >> >> > >> >> > >> >> > >> >> > >> >> > >> >> If I add ActiveX control on a form (WinForm application), > >> >> get a reference to some > >> >> > >> >> =================================== > >> >> This list is hosted by DevelopMentorR http://www.develop.com > >> >> > >> >> View archives and manage your subscription(s) at > >> >> http://discuss.develop.com > >> > > >> > =================================== > >> > This list is hosted by DevelopMentorR http://www.develop.com > >> > > >> > View archives and manage your subscription(s) at > >> > http://discuss.develop.com > >> > >> =================================== > >> This list is hosted by DevelopMentorR http://www.develop.com > >> > >> View archives and manage your subscription(s) at > >> http://discuss.develop.com > > > > =================================== > > This list is hosted by DevelopMentorR http://www.develop.com > > > > View archives and manage your subscription(s) at > > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentorR http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
