views:

84

answers:

2

I have a client server based windows forms application that needs an administrator only screen. The administrator functionality needs to be implemented in such a way that at any given time only one administrator can access that screen. The windows forms client application talks to the server using .NET Remoting. And the server side is distributed on multiple machines.

+2  A: 

This can be done most easily through using a DB table. Typically the DB is already fault tolerant and is a safe resource to use for a shared lock scenario. Just have a lock table that contains some info about the locked resource, who has it, when, etc.

You can also use one of the various "state servers" on the market to store lock state. This is introducing a failure point though, unless you invest in one of the newer distributed state technologies.

However, you are really setting yourself up for further issues. You'll need a screen to allow forcing an unlock, viewing who has the lock, etc. You're best off looking at why this lock is really needed. Is it a technology or business requirement? You can more easily and cleanly implement a pessimistic data updating scenario which would improve user experience.

TheSoftwareJedi
A: 

You need to maintain a static member on the server that indicates if the window is currently in use. Make sure it is thread-safe by using the lock() function when setting the value. You can then check that value before showing the admin screen.

As far as the server side is concerned, you mention that it exists on multiple PC's. Is this a load balanced kind of topolgy which operate as one virtual server? If so you may need to persist the value in a database. Think of it in the same way that ASP.Net persists Session State. I can exist on server, but if there is a server farm it can be moved to SQL Server for use by all servers.

Eric
First paragraph isn't relevant due to server topology. Second paragraph is relevant.
TheSoftwareJedi