我想知道如何启动一个新的AppDomain并在该AppDomain中运行WPF窗口吗?
我的代码如下:
import clr
clr.AddReference(r"wpf\PresentationFramework")
from System.Windows import Application, Window
from System.Threading import Thread, ThreadStart, ApartmentState
from System import AppDomain, AppDomainSetup, CrossAppDomainDelegate
class MyWindow(Window):
...
if __name__ == '__main__':
def start_thread():
thread1 = Thread(ThreadStart(MyWindow))
print ("Thread 1 domain:",thread1.GetDomain().FriendlyName)
thread1.SetApartmentState(ApartmentState.STA)
thread1.Start()
thread1.Join()
ads = AppDomainSetup()
ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory
ads.ConfigurationFile = \
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
ad2 = AppDomain.CreateDomain("ad2", None, ads)
cadd = CrossAppDomainDelegate(start_thread)
ad2.DoCallBack(cadd)
结果,我收到一个错误:
System.Runtime.Serialization.SerializationException:程序集'__CodeGenerator_Assembly,版本= 0.0.0.0,区域性=中性,PublicKeyToken = null'中的类型'__System_CrossAppDomainDelegateDispatcher'未标记为可序列化。
我想面临的挑战是将cadd对象设置为可序列化。但是当我寻找解决方案时,我没有找到有关如何在Python中进行操作的任何信息。
我在这个领域还很陌生,可能一开始我就错了。
谢谢您的帮助!