Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 1.29 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Exposing a winforms application internals through WCF
  2. public partial class Form1 : Form
  3. {
  4.   public Form1()
  5.     {
  6.       InitializeComponent();
  7.       label1.Text = MySingleton.Instance.InitedAt.ToString();
  8.     }
  9. }
  10.  
  11. public class MySingleton
  12. {
  13.   private static MySingleton instance = new MySingleton();
  14.   private DateTime inited;
  15.  
  16.   private MySingleton()
  17.   {
  18.     this.inited = DateTime.Now;
  19.   }
  20.  
  21.   public static MySingleton Instance
  22.   {
  23.     get
  24.     {
  25.       return instance;
  26.     }
  27.   }
  28.  
  29.   public DateTime InitedAt
  30.   {
  31.     get
  32.     {
  33.       return this.inited;
  34.     }
  35.   }
  36. }
  37.        
  38. [ServiceContract]
  39. public interface IApplicationProbe {
  40.  
  41.   [OperationContract]
  42.   string DoesItWork();
  43.  
  44.   [OperationContract]
  45.   string SingletonInited();
  46. }
  47.  
  48. public class ApplicationProbe : IApplicationProbe {
  49.   public string DoesItWork(){
  50.     return "Why yes, yes it does";
  51.   }
  52.  
  53.   public string SingletonInited(){
  54.     return MySingleton.Instance.InitedAt.ToString();
  55.   }
  56. }
  57.        
  58. public class YourImpportantSingleton
  59. {
  60.     public YourImpportantSingleton Instance { get; set; }
  61.     public void DoSeriousBusiness(){...}
  62. }
  63.  
  64. [ServiceContract]
  65. public interface IYourContract
  66. {
  67.     void YourRemoteAction();
  68. }
  69.  
  70. public class YourService : IYourContract
  71. {
  72.     public void YourRemoteAction()
  73.     {
  74.         YourImportantSingleton.Instance.DoSeriousBusiness();
  75.     }
  76. }