Annoyances
Pulled Apart - Part XI: Talking to yourself is ok, but answering back is a problem. Why IMPF destroyed CPUS?
Note: This is part of a series, you can find the rest of the parts in the series index.
Pull for me is as much about learning as it is about writing a useful tool that others will enjoy and often I head down a path to learn it was wrong. Sometimes I realise before a commit and no one ever knows, other times it is committed and reading the source history is like an example of how bad things can get and sometimes I even ship bad ideas. IMPF is one such area where I shipped a huge mistake which caused Pull to easily consume an entire core of CPU for doing zero work.
IMPF would check for messages as using the following process:
The Thread.Sleep(0) is there to ensure application messages get processed, but it is zero so that as soon as a message arrives it is processed. This meant that the check, which did a lot of work, was running almost constantly. This means that Pull ended up eating 100% of a the power of a core ![]()
The Solution
The solution to this was to change the process from constantly checking to getting notified when there is a new message.
This is also much simpler to draw than the other way, maybe that should be a design check, the harder to draw the less chance it works ![]()
The only issue is how do I cause that trigger to fire from another application when it writes a message IMPF should read?
Windows Messaging
Windows internally has a full message system which you can use to send messages to various components in Windows, for example to turn the screen saver on or off, or to send messages to applications. I have used this previously in Pull to tell Windows to add the shield icon if needed (see Part IX) to the protocol handler buttons.
I can also use it to ping an application with a custom message which that application can act on. For Pull when I get that ping I know there is a new IMPF message.
The first part of this is finding the window handle of the primary instance that I want to ping. This I do by consulting the processes running on the machine and using a dash of LINQ filter it to the primary instance.
private static IntPtr GetWindowHandleForPreviousInstances()
{
Process currentProcess = Process.GetCurrentProcess();
string processName = currentProcess.ProcessName;
List<Process> processes = new List<Process>(Process.GetProcessesByName(processName));
IEnumerable<Process> matchedProcesses = from p in processes
where (p.Id != currentProcess.Id) &&
(p.ProcessName == processName)
select p;
if (matchedProcesses.Any())
{
return matchedProcesses.First().MainWindowHandle;
}
return IntPtr.Zero;
}
Now I know who to ping, I just need to send a ping. This is done by calling the Win32 API SendNotifyMessage:
public static int NotifyMessageID = 93956;
private static class NativeMethods
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return:MarshalAs(UnmanagedType.Bool)]
public static extern bool SendNotifyMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
}
public static void PingPreviousInstance()
{
IntPtr otherInstance = GetWindowHandleForPreviousInstances();
if (otherInstance != IntPtr.Zero)
{
NativeMethods.SendNotifyMessage(otherInstance, NotifyMessageID, IntPtr.Zero, IntPtr.Zero);
}
}
That takes care of sending, but how do I receive the ping? I need to do is override the WndProc method on my main form to check for the message and if I get the right ID (see line 1 about – the NotifyMessageID) I then act on it. In my case I use the bus to tell IMPF that there is a new message.
protected override void WndProc(ref Message message)
{
if (message.Msg == WinMessaging.NotifyMessageID)
{
this.bus.Broadcast(DataAction.CheckIPMF);
}
base.WndProc(ref message);
}
This has enabled IMPF to only act when needed, removed a thread (since it no longer needs it’s own thread), simplified the IMPF code and made Pull a better citizen on your machine. Visual Studio and/or Test Manager corrupt licensing?
At the Visual Studio & TFS event we had a few machines complaining that the Test Manager license was invalid and a new one was needed. Those same machines also said Visual Studio’s license was corrupted and that Visual Studio needed a re-install.
To make this more odd, we were using virtual machines so every machine was identical yet only some machines had this problem.
The cause was the host OS date was wrong (the year was 2008) and so the virtual machines were set to 2008. In the eyes of the virtual machine this meant that the license was installed magically in the future.
We turned off the VM, deleted the state, fixed the date and started again and it was solved!
Resolving "Could not load type Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider"
If you are using AppFabric and decide to swop out the ASP.NET standard caching with it you may run into the error:
Could not load type "Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider”
The error will be pointing to the type of the custom session (line 5 below):
<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
<providers>
<!-- specify the named cache for session data -->
<add name="AppFabricCacheSessionStoreProvider"
type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider"
cacheName="TailSpin" sharedId="TailSpinTravelId"/>
</providers>
</sessionState>
The cause is that the application can’t find that class. To help it find it you need to add the following to the Configuration –> System.Web –> Compilation –> Assemblies:
<add assembly="Microsoft.ApplicationServer.Caching.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> <add assembly="Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Cannot open VS project if Blend is used?
I ran into an issue recently after reinstalling my laptop, where I couldn’t open a C# (WPF) project in Visual Studio 2010. Every time I tried it just grimaced at me and said:
Unable to read the project file 'Rule18.csproj'.
E:\Projects\Rule18\Rule18\Rule18.csproj(335,3): The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Expression\Blend\3.1\WPF\Microsoft.Expression.Blend.WPF.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Part of the cause is that previously I had Blend installed, and I had used it on this project to do some fairly complex things, in particular Font Embedding. However since reinstalling I had not installed Blend again.
This is caused the build target file not to be installed, and that caused the error.
How do you get around this?
The best solution is to install the FREE Blend SDK because that will put the build targets on the machine. Links for the SDKs:
- Blend 4 .NET SDK: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=75e13d71-7c53-4382-9592-6c07c6a00207
- Blend 4 Silverlight SDK: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=d197f51a-de07-4edf-9cba-1f1b4a22110d
However I didn’t have time to do this, so as a temporary solution (and definitely not a recommended solution): I opened the project file, and right near the bottom I found the Import for CSharp and Blend. I removed the Blend one, saved and reloaded and worked.
VirtualBox UUID already in use
I am playing around with using VirtualBox to run virtual machines and I ran into an issue trying to use a clone (copy) of a VDI file. The VDI file is the hard disk drive and it has a unique identifier in it it (UUID) and so trying to use a clone of one gives you the error: UUID of the hard disk is already exist in the media registry.
To solve it you need to run the following command to change the UUID of the file:
VBoxManage.exe internal commands sethduuid [VDI file]
Example:
"c:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internal commands sethduuid
AppFabric.vdi
Downloaded PowerPoint files need repairs?
I download a lot of PowerPoint presentations and recently I am seeing more and more are stating they need repairs when opened!
Unfortunately repairing does not work and downloading them again doesn't help either! What is happening is that Windows is detecting that these files are from the Internet and enabling a block on them for your protection. To remove this block, you need to right click the file, select Properties, click the Unblock button and click OK.
You will then be able to open them successfully.
Thanks Joseph for spotting the type-o in the original post.
Paying Nokia for convenience
In the last few weeks I got a Nokia 5800 XpressMusic phone which has been brilliant, and as the geek I am I have been playing around and trying out many of the functions on it. One area which has been an absolute fail, has been the GPS software: Nokia Maps. The phone comes with a 6 month license to get directions or have the phone speak to you as you drive, but at the end of the 6 months you need to pay for these premium services :(
I have no problem paying for it, but the costing model is retarded. This is the pricing when you select it from within the phone:
- 1 day costs R19.99
- 30 days costs R20.00
- 30 days with automatic renewal costs R66
- 1 year costs R512.99
Now I cannot imagine what person would choose 1 day, when 30 days is 1c more expensive, however the part that confuses me is that it is over three times more expensive for the same 30 days with the exception that you are telling Nokia you want to keep up to date with it. The year part is also odd, since if you purchase each month separately it is R240 which is less than half of the year subscription!
Installing MSMQ in Domain Mode on Windows Server 2008
Yesterday I needed to install MSMQ on my laptop which runs Windows Server 2008, which wasn’t as logical as it first appeared.




I am a community lead in this group.