I have an ASP.NET application and I need to serialize access to an
external resource, in this case it's a COM interface to a QuickBooks
application. The SDK for QB exposes a COM component for access to it, but
it is not multithreaded. So I don't think, strictly speaking, I need a
Queue, and all that it usually implies (separate thread reading a
collection of messages). So, the long and the short of it is, I'm
wondering if I can get away with simply using this:

if (!Monitor.TryEnter(object, timeout)) {
  throw Exception("Couldn't get lock.");
}
try {
   // do stuff with COM object...
} finally {
   Monitor.Exit();
}

I'm wondering if I have each ASP.NET thread use this to access the COM
object, I've achieved the serialization I need, and avoided the need for
any separate background thread, Auto/ManualResetEvents, etc.

Is this right, or am I oversimplifying it? I've done multi-threaded apps
before but I'm not an expert, so any help is appreciated.

Thanks!

Andy

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to