pgerard Posted August 25, 2002 Posted August 25, 2002 Hello, I have developped an application which let the user define its own mathematical functions using a subset of VB.Net. I then use Codedom to compile each function into its own assembly. When the user launch a calculation, I load the needed assemblys and use the defined methods. Everything works fine as long as the user don't try to recompile a function (an assembly) which has been loaded in memory. I have not been able to find a way to "unload" an Assembly. As of now, the user has to quit the application and relaunch it (not the optimal solution...) . Does anyone has an idea on how to solve this issue? Thanks for your help Pierre PS : To solve this, the only thing I can think of is to launch another application which would load the assemblies, do the calculations and then communicate the results to the original app, but I have not been able to find any exemple on how to do that so far. Quote
*Gurus* divil Posted August 26, 2002 *Gurus* Posted August 26, 2002 I would suggest setting all references to the assembly equal to Nothing, then calling GC.Collect to force the Garbage Collector to clean up. Let me know how you get on, I'll be needing to do something similar shortly. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Thinker Posted August 26, 2002 *Gurus* Posted August 26, 2002 Can you create a separate AppDomain object to load, run and unload the assemblies in? Quote Posting Guidelines
pgerard Posted August 26, 2002 Author Posted August 26, 2002 Since I asked the question, I have been reading about appdomains. It seems tha Quote
pgerard Posted August 26, 2002 Author Posted August 26, 2002 Oops ... Sorry I pressed enter a bit too fast. As I was saying, I have been looking into that. Unfortunately, I can't seem to find any exemple in VB which would detail something like that and the documentation... well as usual, it is very good when you know what you are lokking for but as for concepts, it is a bit on the short side. If you have any link to a good exemple, that would help a lot. Thanks Pierre Quote
*Gurus* Thinker Posted August 26, 2002 *Gurus* Posted August 26, 2002 Well, when I was looking through msdn.net, I looked at the CreateDomain method of the AppDomain class. It seems like you just declare a variable of type AppDomain and use the CreateDomain method... Dim myDomain As AppDomain = AppDomain.CreateDomain("NewDomain") Then I assume all properties and methods of the class would be available for myDomain, like myDomain.Load(Assemblyname) and maybe myDomain.ExecuteAssembly("myassembly") or myDomain.DoCallBack(callbackdelegate) Here is just a bit of code from MSDN... Public Module PingPong Private greetings As String = "PONG!" Sub Main() Dim currentDomain As AppDomain = AppDomain.CurrentDomain Dim otherDomain As AppDomain = AppDomain.CreateDomain("otherDomain") greetings = "PING!" MyCallBack() otherDomain.DoCallBack(AddressOf MyCallBack) ' Output: ' PING! from default domain ' PONG! from otherDomain End Sub 'Main Sub MyCallBack() Dim name As String = AppDomain.CurrentDomain.FriendlyName Console.WriteLine(greetings + " from " + name) End Sub 'MyCallBack End Module 'PingPong And, of course the the Unload method to shut the AppDomain down (gracefully - must be done executing I believe). Quote Posting Guidelines
pgerard Posted August 27, 2002 Author Posted August 27, 2002 Thanks, looks like that was the right path to follow I have been playing with the domains and it seems to work. The only remaining problem I seem to have is that when the process in the created appdomain takes too long, I seem somehow to get "disconnected". I guess it must be due to some Remoting problem between the two appdomain. I am going to dig into the documentation.... Thanks again Pierre Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.