how to import a function inside other process from host

Mar 11, 2010 at 6:37 AM

Dear EveryOne

i have seen a simple example from Web.

and i modifed the code to try import a part insdie other process from host, but occrued exception.

how can i import a part inside other process from parent process.Is it possible to import a part inside other process from parent process.

i have seen the kind of function from APPDomain, but it isn't safety from thread between parent and child process.

i want to put a part inside child process to prevent a exception  between parent and child process

so i have attached the code below

[HOST Side]

class Program
{
    [Import]
    public IEnumerable<string> Messages { get; set; }

    [Import]
    public IEnumerable<IOutputString> OutputSet { get; set; }

    [Import("OutputMessages")]
    public Action<IEnumerable<IOutputString>, IEnumerable<string>> OutputMessages { get; set; }

    public void Run()
    {
        var catalog = new AggregatingComposablePartCatalog();
          // catalog.Catalogs.Add (new DirectoryPartCatalog(@"..\..\..\ExternalMessages\bin\Debug"));
           catalog.Catalogs.Add(new DirectoryPartCatalog(@"..\..\..\ExtraMessages","*.exe",true));
           catalog.Catalogs.Add (new AttributedAssemblyPartCatalog(Assembly.GetExecutingAssembly()));
        var container = new CompositionContainer(catalog.CreateResolver());
        container.AddPart(this);
        container.Compose();


        OutputMessages(OutputSet, Messages); 
        
    }
    static void Main(string[] args)
    {
        Program p = new Program();
        p.Run();
    }
}
[InterFace]
namespace SharedLibrary
{
    public interface IOutputString
    {
        void OutputString(string value);
    }
}
[ Part made by separte process]
namespace ExternalMessageExe
{
   
    public class Program  
    {
        static void Main(string[] args)
        {
        }

       
    }
    [Export(typeof(IOutputString))]
    public class ExternameMessageEx : IOutputString
    {
        public void OutputString(string value)
        {
            Console.WriteLine("[EXE] Output=" + value);
        }

        [Export]
        public string Message
        {
            get
            {
                return "[EXE]I am starting to get it...";
            }
        }
    }
}