/// <summary> /// アプリケーション定義のパラメーターとエントリポイントを指定して新しいサブプロセスを起動します。 /// </summary> /// <typeparam name="TParameter">サブプロセスに渡されるアプリケーション定義のパラメーターの型。</typeparam> /// <param name="method">サブプロセスの起動後に呼び出されるパブリックな静的メソッド。</param> /// <param name="parameter">サブプロセスに渡されるアプリケーション定義のパラメーター。</param> /// <param name="configuration">サブプロセスの起動設定。</param> /// <returns>サブプロセスの起動タスク。</returns> private Task <Subprocess> StartNewCore <TParameter>(MethodInfo method, TParameter parameter, SubprocessConfiguration configuration) { var conf = configuration ?? new SubprocessConfiguration(); return(OpenTask.ContinueWith(open => { if (!open.IsCompleted) { throw new InvalidOperationException(Resources.FailedToInitializeWcfServiceHost, open.Exception); } var tk = Tuple.Create(typeof(ServiceSubprocessHost <TService>), typeof(TParameter), conf.IsSTAThread, conf.IsWindowsApplication); var asf = GetDynamicEntryPoint( tk, new ServiceSubprocessEntryPointBuilder( typeof(SubprocessArgument <TParameter>), conf.IsSTAThread, conf.IsWindowsApplication, _StartInfoType.MakeGenericType(typeof(TParameter)).GetConstructors()[0], method)); var p = Start(asf, parameter, conf, _Address); lock (InstanceLock) { if (_Clients == null) { _Clients = new Dictionary <int, Subprocess>(); } var dsi = new Subprocess(p); dsi.Exited += Process_Exited; return _Clients[p.Id] = dsi; } })); }
/// <summary> /// アプリケーション定義のパラメーターとエントリポイントを指定して新しいサブプロセスを起動します。 /// </summary> /// <typeparam name="TParameter">サブプロセスに渡されるアプリケーション定義のパラメーターの型。</typeparam> /// <param name="method">サブプロセスの起動後に呼び出されるパブリックな静的メソッド。</param> /// <param name="parameter">サブプロセスに渡されるアプリケーション定義のパラメーター。</param> /// <param name="configuration">サブプロセスの起動設定。</param> /// <returns>サブプロセスの起動タスク。</returns> private Task <Subprocess> StartNewCore <TParameter>(MethodInfo method, TParameter parameter, SubprocessConfiguration configuration) { var conf = configuration ?? new SubprocessConfiguration(); return(Task.Run(() => { var tk = Tuple.Create(typeof(SubprocessHost), typeof(TParameter), conf.IsSTAThread, conf.IsWindowsApplication); var asf = GetDynamicEntryPoint( tk, new SubprocessEntryPointBuilder( typeof(SubprocessArgument <TParameter>), conf.IsSTAThread, conf.IsWindowsApplication, method)); var p = Start(asf, parameter, conf, null); lock (InstanceLock) { if (_Clients == null) { _Clients = new Dictionary <int, Subprocess>(); } var dsi = new Subprocess(p); dsi.Exited += Process_Exited; return _Clients[p.Id] = dsi; } })); }