Skip to main content

Posts

Showing posts from July, 2010

SystemEvents issues

SystemEvents is a class that allows users to receive events that are system-wide. These events range from system time changing (due to daylight savings or time sync or manual time changes) to SessionEnding to LowBattery, to FontsInstalled events, etc. There are many issues with this class 1- It does not work in a Windows Service, unless the service interacts with the desktop (which is an XP feature only). Vista and Windows 7 has an awkward support to say the least for services that interact with the windows desktop. As far as I'm concerned, it is not supported. 2- If you call any SystemEvent.XYZ += OnXYZ;, this ends up creating a hidden window. So what's the problem? if you have any WCF objects that register themselves (using WCF's ServiceHost) in the same thread as the one that called SystemEvents, then all subsequent calls to the WCF services will be serialized on that thread. Most likely that thread is the main UI thread for your application. This results in nasty de...

WCF Dos and Don'ts

Do not inherit interfaces from other interfaces. Interfaces are contracts. Contracts must be explicit, otherwise the flexibility and maintainability of your design would run into issues. An interface is a pure contract definition and should remain explicit and pure. Consider the following example: [ServiceContract] public interface IMyService1 { [OperationContract] void Test1(); } [ServiceContract] public interface IMyService2 : IMyService1 { [OperationContract] void Test2(); } [ServiceBehavior(…)] class MyService : IMyService2, IMyService1 { #region IMyService2 Members public void Test2() { } #endregion #region IMyService1 Members public void Test1() { } #endregion } What happens when you Publish your Service and open its communication channels. If you do the following: ServiceHost serviceHost = new ServiceHost(typeof(MyService, …) ServiceEndpoint ep = serviceHost.AddServiceEndpoint(typeof(IMyService1), typeof(IMyService2)); You will get...