开发者

How to start a WPF application from a web service?

a web service is running with IIS. When calling the initialize service, some libraries are dynamically loaded in order to start a wpf application.

The code compiles, runs... but the window never shows up. No exception is thrown whatsoever.

Below 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 that in a console application, it works perfectly:

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

But if I ru开发者_Go百科n it from the web service, code is correctly executed (as I can debug it, and no exceptions) but the window never shows up:

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

I can see in the process manager that the WPF process is running... Any idea why the window does not show up ?

Regards,

Francois


Is there something special to do to grant all access/rigths to the web service ?


Check your application pool and tell me what user it uses - or if you use impersonation.

My first guess would be that this runs as a service user (with no rights to mess with a desktop and especially not with your desktop). In general I think this is a strange thing to do..

Why don't you use a Silverlight out of browser application? Why no ClickOnce?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜