garbage collection - Disposing ActiveX resources owned by another thread -


I have a problem problem with threading and disposing of resources.

The C # Windows Forms application that runs expensive operations in a thread, this thread instantates an ActiveX control (AxControl). This control should be dealt with because it uses high volume memory so I Applying a displacement method () and even a disaster.

After the thread is terminated, it is said to be the destroyer. It is sad that the UI is called by thread. Then activaxControl.Dispose () invoke; With the message "COM object that has been separated from its built-in RCW" fails, because the object is related to another thread.

How to do this correctly or is it just a bad design that I use?

(I took away the code, including removing any security concerns to minimize it.)

  class program {[STAThread] static zero main () { // do things here, eg open a new thread (new threadstart); // more stuff} Private Zero Runstaff () {DUSTF MATERIAL = NEW DUSTF (); MATERIAL: FormStuff ();}} Category DUSTFOOD: IDisposable { Private AxControl activexControl; DoStuff () {ActivexControl = new AxControl (); activexControl.CreateControl (); // Force Example} ~ DoStuff () {Removal ();} Public Zero Extract () {activexControl.Dispose ();} Public Zero PerformStuff () {// Inventions perpetuum mobile here, takes time}}  

I'm not clear that with an ActiveX control, a disposition method applies. IDisposable pattern managed code To release the .com object, you'll usually use Marshal.ReleaseComObject - you might see your AxControl class Sorry,

Some of the things wrong with the code are incorrect.

You should settle the idisposable doStuff example:

  Private Zero Raster (using (DustF stuff = New DUSTF) } {Stuff.PerformStuff ();}}  

You should not have access to managed resources in the last resource - the last time your customer expires in the case, which then shows the managed execution example

Since you are not using obsolete resources directly in the DUSTF Class So, you probably do not need to finalize, but if you have one, follow the standard IDisposable pattern on MSDN, and do not try to resolve any managed objects.

UPDATE

Note:

is a .NET Interop wrapper DLL which is generated by Visual Studio.

< P> In this case, what is the displacement () method? I do not know that you have an ASP in an ActiveX control Why will I apply the method, in which determiners have been finalized - usually when you are issued the previous COM references, you will clean your

your doStuff.Dispose The method might want to release the COM object, e.g.

  remove public zeros () {activexControl.Dispose (); Marshal.ReleaseComObject (activexControl); }  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -