.net object dispose question

L

laputa

Dear all :

I create a simple code (window application) like following
Private Sub Button1_Click()
Dim Obj As Object
Dim asm As Assembly = Assembly.LoadFrom("TestApp.dll")
Dim ty As Type = asm.GetType("TestApp.appServ")
Obj = Activator.CreateInstance(ty)
Dim Istring As String = Obj.funct()
MessageBox.Show(Istring)
Obj.Dispose()
GC.SuppressFinalize(Obj)

Obj = Nothing
end sub

while TestApp.dll code follow that
using System;
using System.Collections.Generic;
using System.Text;

namespace TestApp
{
public class appServ : IDisposable
{
private bool disposed = false;
public string funct()
{
return "aad";
}
~appServ()
{

// call Dispose with false. Since we're in the
// destructor call, the managed resources will be
// disposed of anyways.
Dispose(false);
}

protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
// dispose-only, i.e. non-finalizable logic
}

// shared cleanup logic
disposed = true;
}
}



public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
GC.Collect();
}

}
}



Before the button click the "TestApp.dll" allow be overwrite
but after button click , the file is locked until the main program exit.
Can anyone tell me how to solve it that I can overwrite dll file without
exit main program

Thanks

Michael
 
A

Anthony Jones

laputa said:
Dear all :

I create a simple code (window application) like following
Private Sub Button1_Click()
Dim Obj As Object
Dim asm As Assembly = Assembly.LoadFrom("TestApp.dll")
Dim ty As Type = asm.GetType("TestApp.appServ")
Obj = Activator.CreateInstance(ty)
Dim Istring As String = Obj.funct()
MessageBox.Show(Istring)
Obj.Dispose()
GC.SuppressFinalize(Obj)

Obj = Nothing
end sub

while TestApp.dll code follow that
using System;
using System.Collections.Generic;
using System.Text;

namespace TestApp
{
public class appServ : IDisposable
{
private bool disposed = false;
public string funct()
{
return "aad";
}
~appServ()
{

// call Dispose with false. Since we're in the
// destructor call, the managed resources will be
// disposed of anyways.
Dispose(false);
}

protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
// dispose-only, i.e. non-finalizable logic
}

// shared cleanup logic
disposed = true;
}
}



public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
GC.Collect();
}

}
}



Before the button click the "TestApp.dll" allow be overwrite
but after button click , the file is locked until the main program exit.
Can anyone tell me how to solve it that I can overwrite dll file without
exit main program

Theres a really useful tool on the web called "Google" you may have heard of
it. Putting "unload assembly" in its search box bring the following blog
link up as the first entry.

http://blogs.msdn.com/jasonz/archive/2004/05/31/145105.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top