9. May 2012 14:04
If you’ve spent any time writing C# using a copy of ReSharper you will have come across the phrase ‘Access to modified closure’. It’s a well known warning and there are plenty of StackOverflow questions and blog posts about it.
I’ve personally run up against this many times, and although I know what to do when it bites me, I’ve never really understood why it was happening. It just never really clicked for me.
Here is some code, as simple as I could make it, that produces the warning and illustrates the behaviour:
var actions = new Action;
for (int i = 0; i < actions.Length; i++)
actions[i] = () => Console.WriteLine(i);
foreach (var action in actions)
The ‘Access to modified closure’ is referring to the use of ‘i’, the loop variable, inside the lambda and being passed to ‘Console.WriteLine’. If you haven’t run into this before you’ll be surprised to find that this code will produce the following output:
5. April 2012 16:20
ILMerge is a great tool for merging .NET assemblies, when we want to deploy an application as a single executable file we can merge in the dependencies and we’re good to go.
Unfortunately ILMerge doesn’t work on WPF applications because according to the ILMerge page on Microsoft Research:
They contain resources with encoded assembly identities. ILMerge is unable to deserialize the resources, modify the assembly identities, and then re-serialize them.
20. March 2012 11:44
I’m working on a multi-tenant web application where I need to have several different login forms for different types of users. For example for Admins, Affiliates, Customers etc.
This causes a problem because the Forms Authentication bits assume there will be a single login page for the whole application and it’s only possible to set a single loginUrl in the web.config to redirect users requesting pages which require authentication.
20. February 2012 16:43
I’ve recently been working on producing my own PCBs at home and ran into the problem of how to reliably and accurately drill the holes I needed.
I had a quick search to see how other people were attacking the problem and managed to find a design for a home made drill press on Instructables which was genius in it’s simplicity. Four hinges and some lengths of timber combine to make an almost perfect plunge action with great accuracy. Here is my take on the idea with photos of the mechanism and a quick video showing it in action. More...
18. February 2012 13:23
In a desktop application I’m working on there are a number of long running batch processes that can be run by the user. This caused problems when the user kicked off a batch process and then walked away from the computer, returning a few hours later to find that the system had gone to sleep and the batch had failed!
A little searching led me to the unmanaged SetThreadExecutionState function which can be used to tell Windows that the calling thread is doing something important which requires the system to be awake. The function can be used in two ways, it can be called repeatedly to reset the system’s idle timer or it can be used in “continuous” mode where the system should not enter sleep mode until told otherwise. Check the MSDN link above for full details. More...
11. July 2010 19:36
Let’s just dive right in and have a demo to see what we’re trying to accomplish. Below is a Silverlight application with some interesting behaviour, if you start changing any data the application will notice and the save button becomes enabled, the state of the form is ‘dirty’. That isn’t very interesting on it’s own, what is interesting is that if you then put the data back to the way it was when you started, the save button becomes disabled again and the form returns to the ‘clean’ state. Here, have a play… More...
12. March 2010 13:18
Jimmy Bogard over at LosTechies has a great little series of posts going ahead at the moment on “strengthening your domain”. For the time constrained amongst us, I’ll quickly summarise his points so you can understand what I say here without going back to the source, however please do go ahead and check them out if your haven’t, there is some great advice there:
It’s his most recent post in the series on encapsulated collections which I’d like to talk more about.
22. December 2009 22:01
Note: This code was written using the PDC09 Beta and may not work without modification on future builds!
Silverlight 4 brings a lot to the table and in my opinion is the most exciting looking release so far. There is a whole slew of new possibilities which have opened up because of a number of important new features, the feature I’m going to be looking at is COM automation.
Huge amounts of functionality built into Windows and installed by third party software is now at your fingertips. So how do we get access to it?
19. December 2009 02:23
So to christen my new home I though I would post a few photos of what I woke up to this morning in deepest Buckinghamshire in the south of England!