IDisposable for dummies #2 – A guide about ‘how to implement it’

IDisposable - How ?In my previous post, I classified the different memory resources available in the .NET CLR and I explained the role of the IDisposable interface as well as the use of the Finalize() method.

In this post, I am going to talk more about the implementation details of IDisposable and Finalize().

For reference, I have split this matter into two posts:

(more…)

Advertisement

IDisposable for dummies #1 – Why? What?

(IDisposable - What ? Why?It took me more than a year to finish writing this article – a “hot topic” and I wanted it to be clear, simple and right. Also, I was busy and did not want to publish anything “unfinished”. As usual, your feedback and comments are more than welcome. Thank you in advance)

Recently (February 2011), I had to review some .NET code and came across of some wrong implementations of IDisposable.

After discussing with the developers, there were many reasons for what I found, ranging from:

  • Not knowing the difference between a “CLR memory resource”, a “managed resource” and an “unmanaged resource”;
  • Not understanding “how and when”  resources are “released”;
  • Not knowing when to override the “Finalize()” method and what should be released by a finalizer?

(more…)

Am I Admin?

This is a quick sample code that I used quite often on customer sites:

  1. To Check whether or not I am a local admin on my machine.
  2. To quickly list what Windows groups my user account is part of.

(more…)

Excel DNA

Recently I was looking at technologies for “Excel Addins” and come across “Excel DNA” (used by some of my colleagues). It is a free framework with a very permissive open-source license.

My need was to be able to consume a WCF service (.NET 3.0) from some VBA code in Excel 2007. Excel-DNA helped to make the final solution very easily. I did a prototype (more…)

How to debug a remote process

Introduction

(original blog entry)

Visual Studio supports remote debugging from one computer to another. When you are doing remote debugging, the host computer can be any platform that supports Visual Studio. The remote computer can be a 32-bit (, Windows 2000, Windows XP, or Windows Server 2003) or 64-bit (IA64, IA64 WOW mode, x64, or x64 WOW mode) platform. (more…)

Configure KDiff3 in Visual Studio

(original)

KDiff3 is a very good comparison and merging tool (You can find it at http://kdiff3.sourceforge.net/). For merging operations bewteen two branches, it allows to see the 3 source views : “base view” (or common ancestor view), “your local branch view” and the “target view”. Also, at the bottom, it displays the final result in the “merged view”. (more…)

How to Debug the Installation/Uninstallation of Windows Service (.NET)

(original blog entry)

Just setup in your “Debug” tab of your Visual Studio “Windows Service” project:

  • Select “Start external program” and find “InstallUtil.exe” (usually under <Windows>\Microsoft.NET)
  • Then as command line argument put the name of your executable
  • As a working directory, select the output folder of your project

It should look like this:

 

Setup the breakpoints and hit F5. The installation should start and stop at your breakpoint.

If you want to debug uninstallation of your Windows Service (.NET), use the “/u” argument of InstallUtil.exe.

If the debug session is aborted (because you stopped it in the middle or an error arose) , then the service might not be completely installed or removed. If that is the case, just open a command line window and type in:

>InstallUtil.exe /u <path:filename of your .NET executable>

Good debug session.

BizTalk SQL Receive Adapter – where to host it?

Currently, I am working on a BizTalk Server 2006 solution and I came across an interesting point about how a SQL receive adapter should be hosted.
Bytheway, I am not the only one with this scenario ; Richard Seroter posted the same issue on his blog, “BizTalk SQL Adapter Advice Requested” (http://blogs.msdn.com/richardbpi/archive/2005/11/22/496020.aspx) .
So, the scenario involves at least two physical servers, each one hosting the same biztalk host, e.g. “host1”. Host1 host many things, and in our case it is the one hosting a SQL receive adapter, e.g. SQL_R1.
The main function of SQL_R1 is to call a stored procedure on a production database, see whether or not there is any work to be picked up. If there is some, then it returns the TOP 10 records (or whatever), and set a flag. All of this is happening inside a distributed transaction (assuming that the production DB is on a different server than the BizTalk MessageBox DB):
– Our production table is enlisted in that transaction
– The BizTalk messagebox which will receive the message is also enlisted in that transaction
Under some circunstances (e.g. loads), a concurrency issue arises: one of the instance of SQL_R1 will have its transaction process terminated by the Resource manager on the production DB server (this is due to lock issues). Ok. this might raise some warnings on the BizTalk server hosting that SQL_R1 which had the error, but the real issue is that after a number of errors raised on the receive location for  SQL_R1, Biztalk will disable that receive location and both instance of SQL_R1 will stop running.
At the moment, the solution I implemented is as follow:
– Create a new host to host the SQL receive adpater.
– Create two host instance (in-process) – one per server (set “do not start” on one of the server).
– Allow the SQL adpter’s receive function to be hosted by the new host.
– Change the setting of the SQL_R1 in my Application to use the new “receive handler host”.
Pros and Cons:
+ we do not have anymore the SQL recieve adapter disabled by BizTalk (the transaction is not anymore terminated)
– We have lost the “automatic failover” facility  on the SQL receive adapter. Now, when the server hosting SQL_R1 is down, we need manually to  start the second host instance for SQL_R1 on the second BizTalk server.
I will carry on searching for other solution/implementation for this scenario.
%d bloggers like this: