IDisposable, destructors and loaded assemblies
-
Hi, in my program, at the constructor of the main driver class, it loads about 6 DLLs (managed) using the Assembly.LoadFile method and then invoking the needed methods using reflections functions. Anyway, when i want to quit the program, sometimes some of the dlls can not be accessed since "they are in use by another program". I've checked the Windows Task Manager and my process do not appear there... any ideas guys? i thought maybe using Dispose procedure or a destructor. can anyone help me with deciding which road to take? and how? 10x
-
Hi, in my program, at the constructor of the main driver class, it loads about 6 DLLs (managed) using the Assembly.LoadFile method and then invoking the needed methods using reflections functions. Anyway, when i want to quit the program, sometimes some of the dlls can not be accessed since "they are in use by another program". I've checked the Windows Task Manager and my process do not appear there... any ideas guys? i thought maybe using Dispose procedure or a destructor. can anyone help me with deciding which road to take? and how? 10x
Don't know if this will help but I have started taking advantage of the "Using" keyword to automatically fire the dispose method. The feature is specific to C# as far as I know. You have to be sure the type you are using implements the IDisposable or it will throw a compile time error. public void YourMethod() { using(MyObj m = new MyObj()) { MyObj.DoWhatYouWant() // Dispose() is called automatically for you when the // Using block exits } } Good luck and I hope it helps.