Hi,
I have webservice which holds a static variable.
I send my first message into the webservice and the static variable gets
a value. If I queried the webservice at a later time (say after 1 hour)
would the static variable still hold the same value, or would the code
be re-initialised and the static variable back to the default value:
//static variable is default 0
//Call webservice
//static variable is set to 1
//Call webservice 1 hour later
//What value is static variable?
My understanding of the webservice process space (in terms of static
vars) was that it matched a windows service, where a static variable
value persisted for the lifetime of the service.
Thanks in advance.
Steven
*** Sent via Developersdex http://www.developersdex.com *** 19 23373
On Jan 10, 10:04 am, Steven Blair <steven.bl...@b tinternet.comwr ote:
<snip>
My understanding of the webservice process space (in terms of static
vars) was that it matched a windows service, where a static variable
value persisted for the lifetime of the service.
It's persisted for the lifetime of the AppDomain. However, ASP.NET may
recycle AppDomains for various reasons, at which point the value of
your variable will be lost.
Jon
Jon
Thanks, I have now turned off the recycling in IIS and seems to be
working fine now.
*** Sent via Developersdex http://www.developersdex.com ***
Just remember that IIS recycling is there for a reason... if you need
persisted state, then perhaps consider using a database? Or
alternatively host via a windows service, not IIS. The latter is easy
to do for WCF, but a little tricker for an "asmx" style web-service.
But a database would be my first instinct...
Marc
As Marc indicated, just "turning off recycling" in IIS is not a very good
guarantee that your app won't lose a static variable's value. If this is the
approach, you may want to modify the Application_Sta rt handler in global.asax
to restore the value on a restart, or use a database or other reliable
persistence mechanism as was suggested.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"Steven Blair" wrote:
Jon
Thanks, I have now turned off the recycling in IIS and seems to be
working fine now.
*** Sent via Developersdex http://www.developersdex.com ***
Well from what I see this is exactly what I want. The application really
does need to be a webservice (for a number of reasons) and I just need
to preserve the application at all times.
What concerns would you have by this approach. Is there soemthing I have
missed?
The overhead of the AppDomain surely its negligible (its a very simple
webservice with a few statics that on each call, creates an instance of
a dll, does some work (consults the static variables) and finishes.
*** Sent via Developersdex http://www.developersdex.com ***
Steven Blair <st**********@b tinternet.comwr ote:
Well from what I see this is exactly what I want. The application really
does need to be a webservice (for a number of reasons) and I just need
to preserve the application at all times.
What concerns would you have by this approach. Is there soemthing I have
missed?
The overhead of the AppDomain surely its negligible (its a very simple
webservice with a few statics that on each call, creates an instance of
a dll, does some work (consults the static variables) and finishes.
1) If your server falls over (e.g. power cut) you've got problems if
you've got no more persistence than memory
2) Changes to the application or its configuration will require
AppDomain recycling
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
well, reboot would be the obvious one...
But also; if your state management is in memory, you have no
opportunity to load-balance / failover. For me, that would be a big
problem. A database (especially on a dedicated server) provides an
abstraction to this, allowing all your servers to share state, and
allowing you to change the cluster on the fly without affecting the
data that people see. Maybe you don't need this level of complexity.
Also - the fact is that occasionally apps die, and it would be
simplistic to assume that the single appdomain is going to run
indefinitely within IIS. A vanilla windows service (since it is much
simpler) will probably run for much longer, but eventually (either due
to an OS restart, or just karma) it will have to be restarted. State
gone.
Marc
Rebooting / crashing is something we considered so we have a primary,
secondary and a tertiary site for such events.
If the box is down, communication is moved over to secondary etc.
If a next communcation came in after a box was rebooted therefore still
accessed the primary, the statics would be lost, but we have a process
in place for this scenario.
Thanks for the advice, and perhaps the next time I appraoch a similar
problem a Database might be considered.
*** Sent via Developersdex http://www.developersdex.com ***
Rebooting / crashing is something we considered so we have a primary,
secondary and a tertiary site for such events.
If the box is down, communication is moved over to secondary etc.
If a next communcation came in after a box was rebooted therefore still
accessed the primary, the statics would be lost, but we have a process
in place for this scenario.
Thanks for the advice, and perhaps the next time I appraoch a similar
problem a Database might be considered.
*** Sent via Developersdex http://www.developersdex.com *** This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Joe Narissi |
last post by:
I know how to create and use static constructors, but is there a such thing
as a static destructor?
If not, then how do you deallocate memory intialized in the static
constructor?
Thanks in advance,
Joe
|
by: xzzy |
last post by:
Using ASP.net, C# and a static class, does the following from MSDN mean:
1. a static hashtable would only live during the session and end when the
session ends
2. there would be a different static hashtable for each session
++ from MSDN ++
|
by: Jack |
last post by:
Thanks.
|
by: junw2000 |
last post by:
When I define a static variable, where is the memory allocated for the
static variable?
Thanks.
Jack
|
by: Morgan Cheng |
last post by:
In the book *Programming C#* 4th editionby Jesse Liberty, it reads
"Actually, the CLR guarantees to start running the static constructor
before anything else is done with your class. However, it only
guarantees to *start* running the static constructor; it doesn't
actually guarantee to *finish* running it." Page 82, Chap 4 Classes and...
| |
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in C# in some
way? Or maybe no, because it is similar to a global variable (with its
scope restricted) which C# is dead against?
Zytan
|
by: Jess |
last post by:
Hello,
I learned that there are five kinds of static objects, namely
1. global objects
2. object defined in namespace scope
3. object declared static instead classes
4. objects declared static inside functions (i.e. local static
objects)
5. objects declared at file scope.
|
by: Pramod |
last post by:
Hello to all of you,
I want to know that what's the use to create static object.
Thanks You
Pramod Sahgal
|
by: mdh |
last post by:
Hi all,
When I try and initialize this static array, as in:
void itoa_recursively(int n, char *s){
static char *p = s;
it fails, yet this:
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |