Sep
17
2009
Warning: rant ahead!
I’m now the sole developer working on arguably one of the largest projects for our company, and things are going well. However, I keep falling into traps and pitfalls created by one of the projects last programmers.
One of his “favourite” tricks seems to be creating a business layer method that populates an object based on data retrieved from a database. Nothing odd there.. but it’s when you have the need to re-use one of his functions that you end up falling right into his carefully seeded trap!
Continue reading
no comments | tags: Annoyances, C#, Laziness, Web | posted in Annoyances, C#
Jul
23
2009
A colleague came to me today asking if I knew of any way to remove the close button from a windows form, but still show the minimize and maximize buttons.
On the face of it, it sounded like an easy answer. I knew you could disable both the minimize and maximize buttons very easily from within the Visual Studio GUI – so surely there’s an option for the third button; the close button?
Actually, no. Whilst you can remove all three buttons in one go (changing the setting “ControlBox” to false.) and as previously mentioned, you can disable the maximize and minimize buttons (“MaximizeBox” and “MinimizeBox” settings respectively), there is no setting to directly control the Close button.
Continue reading
no comments | tags: C#, Tricks, Visual Studio | posted in C#, Computers
Jul
10
2009
I had to make a slight change to one of my applications for a customer today, making it check if it is already running on the local machine and, if it is, abandon it’s attempt to start up another instance.
My initial thoughts were to examine the executing processes and check for the existence of the application in the list:
1
2
3
4
5
6
7
8
| string procName = Process.GetCurrentProcess().ProcessName;
Process[] processes= Process.GetProcessesByName(procName);
if (processes.Length == 1)
{
//run application
...
} |
Now, whilst this works, it is easily “beatable” by simply changing the executable’s name. Doing so will cause the method “GetProcessessByName()” to return only a single match, instead of the current application and any other duplicate instances.
Continue reading
no comments | tags: C#, Mutex, Threading, Tricks | posted in C#, Computers
Jun
12
2009
Anyone who has seen code written by me that requires the invoking of WinForm controls will know that I have an irrational hatred of the “recommended” way of resolving cross-thread operations.
Now, whilst I agree that cross-thread operations should be handled correctly, and I’m actually glad Microsoft decided to tighten its belt over this when it came to creating the dotNet framework, it just seems very “bloaty” to have to write methods such as the following:
Continue reading
2 comments | tags: C#, extension methods, invoke, lambda | posted in C#