Posts

C# Indexer example

public class SampleIndexer { private readonly Dictionary< string ,Dictionary< string , string >> list = new Dictionary< string ,Dictionary< string , string >>(); public SampleIndexer() { list.Add( "One" , new Dictionary< string , string >()); list.Add( "Two" , new Dictionary< string , string >()); } public void Add( string name, string key, string value ) { list[name].Add(key, value ); } public Dictionary< string , string > this [ string name] { get { return list[name]; } } public string this [ string name, string key] { get { return list[name][key]; } } } [TestFixture] public class TestIndexer{ [Test] public void Test() { SampleIndexer indexer = new SampleIndexer(); indexer.Add( "One" , "key1" , ...

C# String.Format("{0}", "formatting string")

Good summary of the String.Format("{0}", "formatting string")

C# Latch implementation

This is a c# Latch implementation for multithreaded applications (equivalent to java CountDownLatch). It’s used in a situation when you have a one thread waiting for a number of other threads to finish. The Test below also uses a Semaphore to run only a specific number of child threads at one time. public class Latch { private readonly object locker = new object (); private int count; public Latch( int noThreads) { lock (locker) { count = noThreads; } } public void Await() { lock (locker) { while (count > 0) { Monitor.Wait(locker); } } } public void CountDown() { lock (locker) { if (--count <= 0) { Monitor.PulseAll(locker); } } } public int GetCount() { lock (locker) { return count; ...

ClickOnce Expired Certification Solution

RenewCert is a solution to Microsoft VS2005 ClickOnce deployment certification problem when it expires after one year. More info about the problem can be found on Microsoft website http://support.microsoft.com/kb/925521

Add, remove, update, query Windows Services from command line

Windows ‘sc’ command can be used to manipulate Windows Services. More info can be found on Microsoft TechNet

Change current directory for Windows Service to application directory

By default current directory for Windows Service is c:\windows\System32 To change it to point to your application directory execute the following in the initialization section of your windows service Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

DataTable not updating when clicked on CheckBox in DataGridView

When you have DataGridView with checkbox column and you click on the checkbox the underlying DataTable is not updated correctly. DataTable is only updated if you move to other row. Not sure why it's like that, but this is a workaround. public void Save(){ DataTable dataTable1 = ((DataTable)dataGridView.DataSource).GetChanges(); //dataTable1 is NULL //revalidate form (fixes the problem) this .ValidateChildren(); DataTable dataTable2 = ((DataTable)dataGridView.DataSource).GetChanges(); //dataTable2 has correct values now }