Hello,
I wrote a little COM-visible dll which can show a WPF window. I set my dll in a VBA script reference (excel -> VBA) and when I run first time everything is OK, after that the VBA sub is finished and I try to run this script again and I get an error message:
"Cannot create more than one System.Windows.Application instance in the same AppDomain."
the relevant part of code:
I wrote a little COM-visible dll which can show a WPF window. I set my dll in a VBA script reference (excel -> VBA) and when I run first time everything is OK, after that the VBA sub is finished and I try to run this script again and I get an error message:
"Cannot create more than one System.Windows.Application instance in the same AppDomain."
the relevant part of code:
…classProgram1{…privatevoidShowWindow(){_MainWindow=newMainWindow();Application app =newApplication();
app.Run(_MainWindow);
app.Shutdown();}publicvoidStartWindow(){
appthread =newThread(ShowWindow);
appthread.Name="wth";
appthread.SetApartmentState(ApartmentState.STA);
appthread.IsBackground=true;
appthread.Start();}…}…