gpt4 book ai didi

caSTLe-windsor - 我可以告诉 CaSTLe Windsor 在单独的 AppDomain 中创建一个组件吗?

转载 作者:行者123 更新时间:2023-12-04 07:04:28 26 4
gpt4 key购买 nike

我创建了一个多线程服务,它使用 CaSTLe Windsor 创建组件以在单独的线程上运行。我使用每个线程的参数按名称解析组件。

我遇到了组件使用的第 3 方库的并发问题。我怀疑将这些组件隔离在单独的 AppDomain 中将解决问题。

有没有办法让 Resolve 使用不同的 AppDomain 创建组件?

private ActivityThread NewActivityThread(ActivityInstance activityInstance)
{
// Set up the creation arguments.
System.Collections.IDictionary arguments = new Dictionary<string, string>();
activityInstance.Parameters.ForEach(p => arguments.Add(p.Name, p.Value));

// Get the activity handler from the container.
IActivity activity = Program.Container.Resolve<IActivity>(activityInstance.Name, arguments);

// Create a thread for the activity.
ActivityThread thread = new ActivityThread(activity, activityInstance, _nextActivityID++);
return thread;
}

public ActivityThread(IActivity activity, ActivityInstance instance, int id)
{
_activity = activity;
_instance = instance;
_id = id;
}

public void Start()
{
if (_thread == null)
{
// Create a new thread to run this activity.
_thread = new Thread(delegate() { _activity.Run(); });
_thread.Name = _activity.ToString();
_thread.SetApartmentState(ApartmentState.STA);
_thread.Start();
}
}

最佳答案

关于caSTLe-windsor - 我可以告诉 CaSTLe Windsor 在单独的 AppDomain 中创建一个组件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1329618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com