Wednesday, June 18, 2014

fast replace by visual studio regular expression

Purpose :
Replacing code.
from simple data holder to wrapper of dictionary.
simple data holder:


After some code refactoring, all data stored in Dictionary, and data holder look like this:



To replace all values (30) data values, i use visual studio find and replace capability to use regular expression.

 This is value of find:
 (\w*) (\w*)\s{ (get;) (set;) }
This is value of replace.
 $1 $2 { get { return dict.GetValue<$1>("$2");} set { dict.SetValue("$2",value); } }

Thursday, November 28, 2013

Winform Gui Thread

You can use this extension to create simple shortcut to Invoke



Example of usage
this.Invoke(() => label1.Text = "complete");

Multithreading : winforms Error handling

This is code handling exceptions from threads.

Sunday, March 13, 2011

deadlocks problem

Today i solve a problem with deadlocks on middle size code-base.
The problem that in this code base the usages of lock implemented by csharp keyword lock (without any timeout system).

I add new class from this site : lock with timeout.
After this i generate search and replace in visual studio 2008 using regexp.

find: lock[ ]*\({[^\)\n]*}\)
replace: using(TimedLock.Lock(\1))

This regexp replacing all lock occurrences (that not commented out) with new timeout locks.
example
lock(myLock)
to
using(TimedLock.Lock(myLock))

Sunday, March 21, 2010

How to improve the code readability/maintenability

After reading this thedailywtf-Unit-Tested article.
I thought that i can add my knowlege how switch from bad code to readable code.

The main concept of the article that i read, that if you add code coverage and a lot of unit test, its great way to improve the software project. And this is only half of the true.

The true is, that when you upgrade to testable code , you just change some code metrics .
This metrics can be calculated by your IDE, the name of the metrics is Coupling and Cyclomatic Complexity.
After that i am play with this metrics (in this game, you need to reduce as much as possible the coupling and CC), the readability of my code is improved drastically and the bugs start to disapear.

Saturday, February 27, 2010

How to boostup the netcf development

Last month i worked on relatively large netcf application.
The problem begins when the executable of program start to be larger then 2 megabait (mostly because of graphics).
The application start to take more than minute of startup time.
So i can't change the program on the fly, as in my usual dotnet development.

Solution: i created new empty project. the project was with same dotnet version, but worked on full dotnet (non netcf).
And add all sources of original project.
Then on "project property"->build-> "conditional compilation symbol" i add DESKTOP.
In every place where the dotnet doesnt work like netcf if added compilation time "#if ,#else, #endif".
(Other possibilty is to use Environment.OSVersion.Platform (that contains PlatformID.WinCE))

There it is, I receive project where i can work as usual, and only when i am done with all small tasks, i am starting with the real netcf work.