473,322 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Multiple application objects?

SL
All,

As I understand it, a single application (i.e. IIS virtual directory)
in ASP.NET may in fact have more than one corresponding
HttpApplicationState object (more or less one per server thread, I
think). During each request, only one of these objects is exposed to
the page as Page.Application. This seems to be supported by the fact
that when I use the debugger, I can see the Application_Start event
firing more than one time even though IIS has not been shut down in
between.

My question is this - within my application, I want to instantiate a
specific COM object, and then I want to store this one instance some
place where it will a) remain until IIS shuts down and b) is
accessible by all pages, during all requests, regardless of exactly
which application object is being used by each request. Due to the
way that this particular COM component was written, I can only have
one instance of the COM object in question at any time. If I try to
have more than one instance exist concurently, they both enter an
invalid state and can no longer be used.

What I initially tried was instantiating my object on
Application_Start, and then saving myObject to the application object.
But later on, Application_Start invariably fires again and I end up
re-creating the object, because I can not see it on the current
application object. Meanwhile the original application object still
has its own instance of my COM object, so two instances now exist but
they both enter an invalid state.

Any help would be greatly appreciated.
Nov 18 '05 #1
3 1895
I'm afraid you're mistaken in your initial premise. There is only one
Application. Check Task Manager if you don't believe me. I have no idea what
you're doing to see the Application_Start event firing more than once, but
it only fires one time when the application starts. When you debug, it will
restart and fire every time you re-run the debugger.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"SL" <sk***********@yahoo.com> wrote in message
news:53**************************@posting.google.c om...
All,

As I understand it, a single application (i.e. IIS virtual directory)
in ASP.NET may in fact have more than one corresponding
HttpApplicationState object (more or less one per server thread, I
think). During each request, only one of these objects is exposed to
the page as Page.Application. This seems to be supported by the fact
that when I use the debugger, I can see the Application_Start event
firing more than one time even though IIS has not been shut down in
between.

My question is this - within my application, I want to instantiate a
specific COM object, and then I want to store this one instance some
place where it will a) remain until IIS shuts down and b) is
accessible by all pages, during all requests, regardless of exactly
which application object is being used by each request. Due to the
way that this particular COM component was written, I can only have
one instance of the COM object in question at any time. If I try to
have more than one instance exist concurently, they both enter an
invalid state and can no longer be used.

What I initially tried was instantiating my object on
Application_Start, and then saving myObject to the application object.
But later on, Application_Start invariably fires again and I end up
re-creating the object, because I can not see it on the current
application object. Meanwhile the original application object still
has its own instance of my COM object, so two instances now exist but
they both enter an invalid state.

Any help would be greatly appreciated.

Nov 18 '05 #2
while there are multiple Application instantences, there is only one cache,
and Application start only fires once per AppDomain.

here is the rub. asp.net will load a new appdomain for your site if it
believes there are any code changes, or that the site needs recycling, or
its hit the timeout. the old appdomain will stay in memory until its
serviced all of its current transactions, and run its shutdown.

while appdomains have their own memory and .net objects are distinct, com
objects use the asp.net memory. you will have to write some unmanaged code
to manage the com objects. the unmanged code will be called by application
start, and return the handle to the com object. it internally will need to
create one instance of the com object and track that its been created.

you also may be able to host the com object in com+ and make it a singleton.

-- bruce (sqlwork.com)
"SL" <sk***********@yahoo.com> wrote in message
news:53**************************@posting.google.c om...
All,

As I understand it, a single application (i.e. IIS virtual directory)
in ASP.NET may in fact have more than one corresponding
HttpApplicationState object (more or less one per server thread, I
think). During each request, only one of these objects is exposed to
the page as Page.Application. This seems to be supported by the fact
that when I use the debugger, I can see the Application_Start event
firing more than one time even though IIS has not been shut down in
between.

My question is this - within my application, I want to instantiate a
specific COM object, and then I want to store this one instance some
place where it will a) remain until IIS shuts down and b) is
accessible by all pages, during all requests, regardless of exactly
which application object is being used by each request. Due to the
way that this particular COM component was written, I can only have
one instance of the COM object in question at any time. If I try to
have more than one instance exist concurently, they both enter an
invalid state and can no longer be used.

What I initially tried was instantiating my object on
Application_Start, and then saving myObject to the application object.
But later on, Application_Start invariably fires again and I end up
re-creating the object, because I can not see it on the current
application object. Meanwhile the original application object still
has its own instance of my COM object, so two instances now exist but
they both enter an invalid state.

Any help would be greatly appreciated.

Nov 18 '05 #3
Bruce,

Thanks very much for the reply.

I had thought I had seen a post indicating that there is more than one
application object, which I thought explained the behavior I've been
seeing.

I've mostly been using the application with the VS.NET debugger, which
combined with the fact that this COM object only allows one instance at
a time, has been causing me all sorts of problems. In any case your
explanation of when the application starts and stops in relation to the
debugger is a big help.

Do you know if, when the server restarts the application due to the
debugger or a detected code change, the Application_End event reliably
fires? In my initial attempt to make this all work, I creted the
object in application_Start and properly disposed of it in the
application_end event, but at least in debugging I still had problems
from multiple instances of the COM object.

I don't have the source code to the COM object in question and I won't
be able to get it, so modifying it at that level is not in the cards.
In fact, I've spoken to the developer of the COM object, and it was
written in VB6 as an ActiveX EXE but was not written as a singleton.

Thanks in advance for any help.
bruce barker wrote:
while there are multiple Application instantences, there is only one cache, and Application start only fires once per AppDomain.

here is the rub. asp.net will load a new appdomain for your site if it believes there are any code changes, or that the site needs recycling, or its hit the timeout. the old appdomain will stay in memory until its
serviced all of its current transactions, and run its shutdown.

while appdomains have their own memory and .net objects are distinct, com objects use the asp.net memory. you will have to write some unmanaged code to manage the com objects. the unmanged code will be called by application start, and return the handle to the com object. it internally will need to create one instance of the com object and track that its been created.
you also may be able to host the com object in com+ and make it a singleton.
-- bruce (sqlwork.com)
"SL" <sk***********@yahoo.com> wrote in message
news:53**************************@posting.google.c om...
All,

As I understand it, a single application (i.e. IIS virtual directory) in ASP.NET may in fact have more than one corresponding
HttpApplicationState object (more or less one per server thread, I
think). During each request, only one of these objects is exposed to the page as Page.Application. This seems to be supported by the fact that when I use the debugger, I can see the Application_Start event
firing more than one time even though IIS has not been shut down in
between.

My question is this - within my application, I want to instantiate a specific COM object, and then I want to store this one instance some place where it will a) remain until IIS shuts down and b) is
accessible by all pages, during all requests, regardless of exactly
which application object is being used by each request. Due to the
way that this particular COM component was written, I can only have
one instance of the COM object in question at any time. If I try to have more than one instance exist concurently, they both enter an
invalid state and can no longer be used.

What I initially tried was instantiating my object on
Application_Start, and then saving myObject to the application object. But later on, Application_Start invariably fires again and I end up re-creating the object, because I can not see it on the current
application object. Meanwhile the original application object still has its own instance of my COM object, so two instances now exist but they both enter an invalid state.

Any help would be greatly appreciated.


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: TT (Tom Tempelaere) | last post by:
Hi there, In my application I have a panel that contains a matrix of user controls. The user control is fairly simple. It merely draws a circle that represents an object in my code. The object...
6
by: mark | last post by:
I have an asp.net ecommerce web application on a remote web server. I'm using an Access database on the back end. I've notice a few strange things. When I mimic an multiple user environment by...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
2
by: Tumurbaatar S. | last post by:
ASP.NET QuickStart Tutorial says that: .... ASP.NET maintains a pool of HttpApplication instances over the course of a Web application's lifetime. ASP.NET automatically assigns one of these...
9
by: Graham | last post by:
I have been having some fun learning and using the new Controls and methods in .Net 2.0 which will make my life in the future easier and faster. Specifically the new databinding practises and...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
0
by: Sebastian Loncar | last post by:
Hi, i have two applications, which communicates very extrem together. With the IPC-Channel i receive often the messages like "all instances of the requested pipe are busy". So i want to use...
3
by: breeto | last post by:
If you've configured .NET Remoting to use more than one channel of the same type, for example two TcpClientChannels with unique names, when you want to create a proxy to a remote object how do you...
2
by: polocar | last post by:
Hi, I'm writing a program using Visual C# 2005 Professional Edition, and I was trying to assign multiple MainMenu objects (one by one, of course) to the same Form (let's suppose 2 MainMenu...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.