I'm compiling a DLL at runtime and then run it:

```
private void RunDll2(string path, string typename)
{
    AppDomain newDomain = AppDomain.CreateDomain("newDomain");
    AssemblyName assemblyName = AssemblyName.GetAssemblyName(path);

    Command cmd = (Command)newDomain.CreateInstanceAndUnwrap(assemblyName.FullName, typename);
    cmd.Execute();
    cmd = null;
}

```

This works one time, but if I want to compile the DLL with another code (same file) it gives me the error: File is used by another process!
Then I have to restart the application!

How can I unload the assembly when the Code in it is finished?

EDIT: 

Code of the ´Command´ class:

```
using System;

namespace NWT_Projekt
{
    public interface Command
    {
        void Execute();
    }
}

```

Code of the Dll:

```
using System;
using System.Collections;
using System.Xml;
using System.IO;
using System.Windows.Forms;

namespace NWT_Projekt
{
    [Serializable()]
    public class TestClass : NWT_Projekt.Command
    {
        public MainForm f;

        public TestClass()
        {
            f = Form.ActiveForm as MainForm;
        }

        void wait(int sec)
        {
            for (int i = 0; i <= sec / 10; i++)
            {
                System.Threading.Thread.Sleep(10);
                Application.DoEvents();
            }
        }

        public void Execute()
        {
            //Here is different code each time I compile it
        }
    }
}

```