c# - WCF hosted in WPF and how can i change control in MainWindow UI from wcf? -
i write wcf code , hosted in wpf app. write class switch mainwindow show other page in project
public static class switcher { public static mainwindow pageswitcher; public static void switch(page newpage) { pageswitcher.navigate(newpage); } }
and write wcf service this:
[servicecontract] public interface iappmanager { [operationcontract] void dowork(); [operationcontract] void page1(); [operationcontract] void page2(); } [servicebehavior(instancecontextmode = instancecontextmode.percall, concurrencymode = concurrencymode.multiple)] public class appmanager : iappmanager { public void dowork() { } public void page1() { mainwindow.pageswitcher = new mainwindow(); mainwindow.switch(new page1()); } public void page2() { mainwindow.pageswitcher = new mainwindow(); mainwindow.switch(new page2()); } }
i want change page remotely computer wcf not work , trace code wcf run , response not how can access main thread change ui page or other element?
your current solution unusual, wcf can hosted in wpf application. should never try directly manipulate ui wcf service - you'll have cross thread issues begin with.
what should consider doing using messaging via pub-sub broker (image linked msdn):
something fits bill nicely prism's eventaggregator. couple of samples cherry picked simplifying prism’s eventaggregator , prism eventaggregator sample.
the way use service registers events , raises them, wpf subscribes events , processes them. can specify whether receive events on ui thread or background thread.
Comments
Post a Comment