When Building Multi-Threaded Applications using ThreadPool, Make the Number of Worker Threads Configurable

Just a simple thought, when creating a multi-threaded applications, make the number of threads configurable. ThreadPool has this behavior that it will immediately set the minimum worker threads equal to the number of logical processors in your machine, and set the maximum to 250 per logical processor, well documented in msdn (.Net Framework 2.0 SP1)….


String.Split has High Cost on Performance

One application had a memory issue, it just consume too much resources. The application performed well, but it is very obvious when we saw the performance counters, something can be done to make it better. Reviewing the code did not reveal something significant, the code already allocated objects that are necessary. The code parses a…


How to Create Custom Event Log for Windows Service

When you created a Windows Service, you usually add a Service Installer to allow this service to be installed using InstallUtil or installing it programmatically like this post shows you. The service installer will create the Event Log for the service, and by default it is "Application", and the source is the name of your…


How to Get IIS Web Sites Information Programmatically

I needed to get the location of IIS log files on my servers, after doing a quick investigation, I am quite amazed on how much information are exposed via managed code. This snippet will return the name of the sites and the location of the log files. foreach (DirectoryEntry Site in new DirectoryEntry("IIS://" + System.Environment.MachineName…


Watch PDC Videos Online

PDC is almost over, did you know that you can access the recorded sessions online? Go to http://www.microsoftpdc.com, and click on Agenda on the top. then click on Sessions tab. Pick the session that you want to watch, scroll down, you should see a Video tab. Much shorter shortcut, got to this link https://sessions.microsoftpdc.com/public/timeline.aspx. Today…


How to Install Windows Service Programmatically

Sometimes you may want to install a Windows Service programmatically, but the target machine does not have InstallUtil.exe. To install a Windows Service programmatically, you can build an application to install that Windows Service. Add a reference to System.Configuration.Install Use this code: public static void InstallService(string ExeFilename) { System.Configuration.Install.AssemblyInstaller Installer = new System.Configuration.Install.AssemblyInstaller(ExeFilename); Installer.UseNewContext =…


How to Install Assemblies to the GAC Programmatically?

You can add or remove assemblies from the GAC using code. You can use Publish.GacInstall method to install an assembly to the GAC, or Publish.GacRemove method to remove that assembly from the GAC. If you are using Vista, and enable UAC, you have to run this code using elevated command (run as Administrator), otherwise it…


"Access Denied" When Accessing a Share in Windows Home Server

This is the scenario, as WHS Administrator, you granted yourself access to a specific share, and you are trying to connect to that share, and then you get an access denied error message. What is going on? You are currently have some work open, and you pretty much does not have time to reboot your…


Advice for New Programmers

I was reading an old post that Chuck Jazdzewski wrote. This one is really good, it is not applicable only for new programmers, if you are a seasoned programmer, this article is still a good read. Jump to Chuck’s fatherly advice for new programmers.


In God We Trust, Everybody Else Must Bring Data

One day, I was presented with a problem, that the finalizer was not called during application pool recycle. I was busy, so I did not have chance to respond. Later on, I checked the code, it was modified to inherit from CriticalFinalizerObject class, and a comment saying that even though the class is inherited from…