In anther thread I learned that I could set up a static member to act as
a kind of global variable for a web service; one that could be managed
for multiple access using a mutex.
Now I am thinking of other uses.
For example, say I want to provide data validation on a field based on a
table from a database.
So, I would want to load that list once from a table, and then have all
web method calls use that static property ( let's make it an array in
this case ).
So, what I need is a way to initialize the array once from the database.
Can I do this in InitializeComponent() -- that is, is that method
invoked only once? or each time the web service is called ? 7 1639
The typical place for initializing static fields is in a static constructor,
e.g.
class SomeClass
{
private static ArrayList someData = null;
static SomeClass()
{
someData = new ArrayList();
someData.Add("one");
someData.Add("two");
}
}
The static constructor is guaranteed to be called before any references to
any static fields.
Ken
"john bailo" <ja*****@earthlink.net> wrote in message
news:2v*************@uni-berlin.de... In anther thread I learned that I could set up a static member to act as a kind of global variable for a web service; one that could be managed for multiple access using a mutex.
Now I am thinking of other uses.
For example, say I want to provide data validation on a field based on a table from a database.
So, I would want to load that list once from a table, and then have all web method calls use that static property ( let's make it an array in this case ).
So, what I need is a way to initialize the array once from the database.
Can I do this in InitializeComponent() -- that is, is that method invoked only once? or each time the web service is called ?
Ok, great.
So then I will assume that this works the same in the class that derives
from System.Web.Services.WebService
Gee, I'm surprised that this static thing is not cited more as a way to
create global application wide variables and resources...it seems really
powerful for web services...
Ken Kolda wrote: The typical place for initializing static fields is in a static constructor, e.g.
class SomeClass { private static ArrayList someData = null;
static SomeClass() { someData = new ArrayList(); someData.Add("one"); someData.Add("two"); } }
The static constructor is guaranteed to be called before any references to any static fields.
Ken
"john bailo" <ja*****@earthlink.net> wrote in message news:2v*************@uni-berlin.de...
In anther thread I learned that I could set up a static member to act as a kind of global variable for a web service; one that could be managed for multiple access using a mutex.
Now I am thinking of other uses.
For example, say I want to provide data validation on a field based on a table from a database.
So, I would want to load that list once from a table, and then have all web method calls use that static property ( let's make it an array in this case ).
So, what I need is a way to initialize the array once from the database.
Can I do this in InitializeComponent() -- that is, is that method invoked only once? or each time the web service is called ?
But for a web service, I cannot declare the constructor static.
Does this constructor get called once -- or each time the web service is
called?
Ken Kolda wrote: The typical place for initializing static fields is in a static constructor, e.g.
class SomeClass { private static ArrayList someData = null;
static SomeClass() { someData = new ArrayList(); someData.Add("one"); someData.Add("two"); } }
The static constructor is guaranteed to be called before any references to any static fields.
Ken
"john bailo" <ja*****@earthlink.net> wrote in message news:2v*************@uni-berlin.de...
In anther thread I learned that I could set up a static member to act as a kind of global variable for a web service; one that could be managed for multiple access using a mutex.
Now I am thinking of other uses.
For example, say I want to provide data validation on a field based on a table from a database.
So, I would want to load that list once from a table, and then have all web method calls use that static property ( let's make it an array in this case ).
So, what I need is a way to initialize the array once from the database.
Can I do this in InitializeComponent() -- that is, is that method invoked only once? or each time the web service is called ?
You would create a static constructor in addition to your normal
constructor. Every class can have a static constructor, whether it is a web
service or otherwise. It is guaranteed to be called only once during the
lifetime of the app and will always be called before any static data is
accessed or any instances are created. Check out the C# reference document
regarding static constructors: http://msdn.microsoft.com/library/en...spec_10_11.asp
Ken
"John Bailo" <ja*****@earthlink.net> wrote in message
news:ty*****************@newsread1.news.pas.earthl ink.net... But for a web service, I cannot declare the constructor static.
Does this constructor get called once -- or each time the web service is called?
Ken Kolda wrote: The typical place for initializing static fields is in a static
constructor, e.g.
class SomeClass { private static ArrayList someData = null;
static SomeClass() { someData = new ArrayList(); someData.Add("one"); someData.Add("two"); } }
The static constructor is guaranteed to be called before any references
to any static fields.
Ken
"john bailo" <ja*****@earthlink.net> wrote in message news:2v*************@uni-berlin.de...
In anther thread I learned that I could set up a static member to act as a kind of global variable for a web service; one that could be managed for multiple access using a mutex.
Now I am thinking of other uses.
For example, say I want to provide data validation on a field based on a table from a database.
So, I would want to load that list once from a table, and then have all web method calls use that static property ( let's make it an array in this case ).
So, what I need is a way to initialize the array once from the database.
Can I do this in InitializeComponent() -- that is, is that method invoked only once? or each time the web service is called ?
Will I ever be as smart as you ?
Thanks again for the help !
Ken Kolda wrote: You would create a static constructor in addition to your normal constructor. Every class can have a static constructor, whether it is a web service or otherwise. It is guaranteed to be called only once during the lifetime of the app and will always be called before any static data is accessed or any instances are created. Check out the C# reference document regarding static constructors:
http://msdn.microsoft.com/library/en...spec_10_11.asp
Ken
"John Bailo" <ja*****@earthlink.net> wrote in message news:ty*****************@newsread1.news.pas.earthl ink.net...
But for a web service, I cannot declare the constructor static.
Does this constructor get called once -- or each time the web service is called?
Ken Kolda wrote:
The typical place for initializing static fields is in a static constructor, e.g.
class SomeClass { private static ArrayList someData = null;
static SomeClass() { someData = new ArrayList(); someData.Add("one"); someData.Add("two"); } }
The static constructor is guaranteed to be called before any references to any static fields.
Ken
"john bailo" <ja*****@earthlink.net> wrote in message news:2v*************@uni-berlin.de...
In anther thread I learned that I could set up a static member to act as a kind of global variable for a web service; one that could be managed for multiple access using a mutex.
Now I am thinking of other uses.
For example, say I want to provide data validation on a field based on a table from a database.
So, I would want to load that list once from a table, and then have all web method calls use that static property ( let's make it an array in this case ).
So, what I need is a way to initialize the array once from the database.
Can I do this in InitializeComponent() -- that is, is that method invoked only once? or each time the web service is called ?
Ok, running in the debugger, I saw some things that made me change your
strategy slightly.
1. I was able to /overload/ the constructor with an addition one of type
static; however, that constructor executed each time the web service was
called -- not what I wanted.
2. The only reason I was doing that is to load the XmlDocument with an
XmlReader -- which could not be done in the XmlDocument constructor ( it
requires execution of the .Load method ).
3. I created a new class, that takes an XmlReader in as part of its
constructor and I instantiate the new class as static in the web service
-- so it only seems to execute the .Load method once.
Ken Kolda wrote: You would create a static constructor in addition to your normal constructor. Every class can have a static constructor, whether it is a web service or otherwise. It is guaranteed to be called only once during the lifetime of the app and will always be called before any static data is accessed or any instances are created. Check out the C# reference document regarding static constructors:
http://msdn.microsoft.com/library/en...spec_10_11.asp
Ken
"John Bailo" <ja*****@earthlink.net> wrote in message news:ty*****************@newsread1.news.pas.earthl ink.net...
But for a web service, I cannot declare the constructor static.
Does this constructor get called once -- or each time the web service is called?
Ken Kolda wrote:
The typical place for initializing static fields is in a static constructor, e.g.
class SomeClass { private static ArrayList someData = null;
static SomeClass() { someData = new ArrayList(); someData.Add("one"); someData.Add("two"); } }
The static constructor is guaranteed to be called before any references to any static fields.
Ken
"john bailo" <ja*****@earthlink.net> wrote in message news:2v*************@uni-berlin.de...
In anther thread I learned that I could set up a static member to act as a kind of global variable for a web service; one that could be managed for multiple access using a mutex.
Now I am thinking of other uses.
For example, say I want to provide data validation on a field based on a table from a database.
So, I would want to load that list once from a table, and then have all web method calls use that static property ( let's make it an array in this case ).
So, what I need is a way to initialize the array once from the database.
Can I do this in InitializeComponent() -- that is, is that method invoked only once? or each time the web service is called ?
Creating a static constructor isn't the same thing as creating an overloaded
constructor. Your code should have looked like:
public class MyWebService
{
private static XmlDocument someDocument = null;
// Static constructor -- note that "static" keyword instead of
public/private
static MyWebService()
{
// Init the XML document
someDocument = new XmlDocument();
someDocument.Load(...);
}
// Instance constructor
public MyWebService()
{
// Use the document
string name = someDocument.documentElement.Name;
// ...
}
}
The instance constructor will be called once per page hit, but the static
constructor should get called once prior to the first instance constructor.
Ken
"John Bailo" <ja*****@earthlink.net> wrote in message
news:I5*****************@newsread1.news.pas.earthl ink.net... Ok, running in the debugger, I saw some things that made me change your strategy slightly.
1. I was able to /overload/ the constructor with an addition one of type static; however, that constructor executed each time the web service was called -- not what I wanted.
2. The only reason I was doing that is to load the XmlDocument with an XmlReader -- which could not be done in the XmlDocument constructor ( it requires execution of the .Load method ).
3. I created a new class, that takes an XmlReader in as part of its constructor and I instantiate the new class as static in the web service -- so it only seems to execute the .Load method once. Ken Kolda wrote: You would create a static constructor in addition to your normal constructor. Every class can have a static constructor, whether it is a
web service or otherwise. It is guaranteed to be called only once during the lifetime of the app and will always be called before any static data is accessed or any instances are created. Check out the C# reference
document regarding static constructors:
http://msdn.microsoft.com/library/en...spec_10_11.asp Ken
"John Bailo" <ja*****@earthlink.net> wrote in message news:ty*****************@newsread1.news.pas.earthl ink.net...
But for a web service, I cannot declare the constructor static.
Does this constructor get called once -- or each time the web service is called?
Ken Kolda wrote:
The typical place for initializing static fields is in a static
constructor,
e.g.
class SomeClass { private static ArrayList someData = null;
static SomeClass() { someData = new ArrayList(); someData.Add("one"); someData.Add("two"); } }
The static constructor is guaranteed to be called before any references
to
any static fields.
Ken
"john bailo" <ja*****@earthlink.net> wrote in message news:2v*************@uni-berlin.de...
>In anther thread I learned that I could set up a static member to act
as>a kind of global variable for a web service; one that could be managed >for multiple access using a mutex. > >Now I am thinking of other uses. > >For example, say I want to provide data validation on a field based on
a>table from a database. > >So, I would want to load that list once from a table, and then have
all>web method calls use that static property ( let's make it an array in >this case ). > >So, what I need is a way to initialize the array once from the
database.> >Can I do this in InitializeComponent() -- that is, is that method >invoked only once? or each time the web service is called ? > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paolo Losi |
last post by:
Hi all,
I'm pretty new to the python language so please excuse me
if this is FAQ... I'm very glad to be part of the list! :-)
I'm looking into a way to implement a generic workflow framework...
|
by: Sean R. Lynch |
last post by:
I've been playing around with Zope's RestrictedPython, and I think I'm
on the way to making the modifications necessary to create a
capabilities-based restricted execution system. The idea is to...
|
by: Jenny Zhang |
last post by:
The osdl-dbt3 test starts with building and vacuuming the database.
The execution plans were taken after the vacuuming.
I did two tests with the same database parameters:
1. run two osdl-dbt3...
|
by: Johannes Lebek |
last post by:
Hi there,
lately, I experienced a strange thing on my DB2 V8.1 on Windows: Some
queries took a very long time. A snapshot discovered the following:
Number of executions = 47...
|
by: Beni |
last post by:
I have been programming in C for about a year now. It sounds silly,
but I never took the time to question why a C(or C++ or Java) program
execution begins only at the main(). Is it a convention or...
|
by: iam980 |
last post by:
Hello All.
We have tested following SQL script from query analyzer:
-- Script begin
DECLARE @I int;
SET @I = 1;
WHILE @I < 10000000 BEGIN
SET @I = @I + 1;
END
-- Script end
|
by: Ina Schmitz |
last post by:
Hi NG,
does IBM Universal Database 8.2 make any difference between actual and
estimated execution plans like in SQL Server ("set showplan_all on" for
estimated execution plan and "set statistics...
|
by: romixnews |
last post by:
Hi,
I'm facing the problem of analyzing a memory allocation dynamic and
object creation dynamics of a very big C++ application with a goal of
optimizing its performance and eventually also...
|
by: TheRealPawn |
last post by:
I'm trying to get the execution plan for a single stored procedure
from Profiler. Now, I've isolated the procedure but I get all
execution plans. Any ideas on how to connect the SPIDs so that I...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
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)...
|
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....
|
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
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |