How to start a WPF application from a web service?

The web service works with IIS. When the initialization service is called, some libraries are dynamically loaded to start the wpf application.

The code compiles, runs ... but the window never appears. No exception is thrown.

The following is the code that is executed to create the WPF application:

public void Start()
{
 ThreadStart ts = Run;
        Thread t = new Thread(ts);
        t.SetApartmentState(ApartmentState.STA);
        t.Start();
}

[STAThread]
public void Run()
{
 try
        {
         App app = new App();
                MainWindow w = new MainWindow();
                w.Show();
                app.Run(w);
        } catch (Exception e)
        {
         LogManager.GetLogger("general").Debug(e.StackTrace);
        }
}

If I run this in a console application, it works fine:

   static void Main(string[] args)
   {
       MyApplication app = new MyApplication();
       app.Start();
       Console.ReadKey();
   }

But if I run it from a web service, the code will execute correctly (how can I debug it, and no exceptions), but the window never appears:

public void initialize() {
 IMyApplication application = assembly.CreateInstance(namespaceValue + ".MyApplication") as IMyApplication;
        application.Start();
}

In the process manager, I see that the WPF process is running ... Any idea why the window is not showing?

Hello,

Francois


Is there anything special to provide all access / bindings to the web service?

+3
1

, , .

, ( , , ). , , .

Silverlight ? ClickOnce?

+1

Source: https://habr.com/ru/post/1727747/


All Articles