Hi guys,
I want to write some global functions which can be called from
different asp.net page.
In Visual Basic, there is a global module which allow me to do that.
In Visual Basic .net, I have to create a class file to host these
functions.
And every time when I need to call these functions, I have to create a
object.
If I don't want to create a object every time, I need to make these
functions as shared.
However, is it true that shared function will store all local variable
in same place even when being called in multi-thread environment?
For example:
Public Class MyClass
Publich Shared Sub MySub
Dim a as integer
........
End Sub
End class
If MyClass.MySub is called by multi-thread, will it cause error
because there is only one copy of local variable "a"?
Second question: in asp.net is there any other way to implement global
function, without using OOP?
Thank you.
Henry 2 1664
As long as all the threads are in the same process, there will be 1 instance
of anything shared.
You can put your global function in a Module (don't need the word Shared in
this case). However, a Module gets compiled down to a class with all shared
functions anyway, but it might be more syntactically convenient for you to
do so. This would be a VB thing only.
"Henry" <ea*******@yaho o.com> wrote in message
news:25******** *************** **@posting.goog le.com... Hi guys,
I want to write some global functions which can be called from different asp.net page. In Visual Basic, there is a global module which allow me to do that.
In Visual Basic .net, I have to create a class file to host these functions. And every time when I need to call these functions, I have to create a object. If I don't want to create a object every time, I need to make these functions as shared. However, is it true that shared function will store all local variable in same place even when being called in multi-thread environment? For example:
Public Class MyClass
Publich Shared Sub MySub Dim a as integer ........
End Sub
End class
If MyClass.MySub is called by multi-thread, will it cause error because there is only one copy of local variable "a"?
Second question: in asp.net is there any other way to implement global function, without using OOP?
Thank you.
Henry
"Henry" <ea*******@yaho o.com> wrote in message
news:25******** *************** **@posting.goog le.com... Hi guys,
I want to write some global functions which can be called from different asp.net page. In Visual Basic, there is a global module which allow me to do that.
In Visual Basic .net, I have to create a class file to host these functions. And every time when I need to call these functions, I have to create a object. If I don't want to create a object every time, I need to make these functions as shared. However, is it true that shared function will store all local variable in same place even when being called in multi-thread environment? For example:
Public Class MyClass
Publich Shared Sub MySub Dim a as integer ........
End Sub
End class
If MyClass.MySub is called by multi-thread, will it cause error because there is only one copy of local variable "a"?
No. "a" will be local. The problem you may have heard about is the
following:
Public Class MyClass
Private Shared beVeryCareful As Integer
Public Shared Sub MySub
beVeryCareful = beVeryCareful + 1
End Sub
End Class
"beVeryCare ful" will be shared by all threads. Since the modification is not
synchronized, you'll have a race condition on your hands.
Second question: in asp.net is there any other way to implement global function, without using OOP?
Why would you not want to use OOP?
As you become more accustomed to it, you'll find that you write fewer and
fewer "global functions". I find that once I start using classes to keep
related functions together, that I begin to find relationships between the
classes. I also tend to find that these functions are operating on the same
pieces of data over and over. This makes them strong candidates for becoming
a class, where the data they manipulate becomes class member data, and each
set of data becomes an instance of the class.
John Saunders This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Tyler |
last post by:
PHP puts most of its functions into a big flat global namespace.
That leads to short function names - but creates a namespace
minefield for programmers.
Lots of the functions are legacies from the days before PHP
got object-oriented features.
For instance we currently have:
|
by: Andrew V. Romero |
last post by:
I have been working on a function which makes it easier for me to pull
variables from the URL. So far I have:
<script language="JavaScript">
var variablesInUrl;
var vArray = new Array();
function loadUrlVariables()
{
varString = location.search;
|
by: Phil Lamey |
last post by:
Hi All,
I have the following code but for some reason I cannot get the Session_OnEnd
event to fire.
I am trying to limit the amount of connections a browser session can have.
Where the application is a virtual directory.
Any ideas?
------------
|
by: lawrence |
last post by:
I'm learning Javascript. I downloaded a script for study. Please tell
me how the variable "loop" can have scope in the first function when
it is altered in the second function? It is not defined in global
space, therefore it is not a global variable, yes? Even if it was
global, how would it get from one function to another? In PHP
variables are copied by value. Are they copied by reference in
Javascript?
<SCRIPT LANGUAGE="JavaScript">
|
by: Michael |
last post by:
Hi newsgroup,
as the subject indicates I am looking for an advice
using global variables. I am not if this problem is more
about style then C. If its wrong in thi group, sorry.
So I have a couple of function that all need the same
information (all located in the same file). By now it looks like
/* file beginns */
| |
by: Roman Ziak |
last post by:
Hello,
there were times when I used to be looking for a way to access
JavaScript Global object similar to those found in VBScript or PHP
($GLOBALS). At present this has only academic value for me. I was doing
research on JavaScript inheritance recently (simplifying it in
particular) and after reading 10.1.1, 10.1.3 and some other sections of
ECMA262 I got a hint on accessing global object from different than
global scope.
|
by: hynek.cihlar |
last post by:
A strange behaviour thatI found in ASP.NET 2.0.
I am trying to issue a callback request (handled by
ICallbackEventHandler and RaiseCallbackEvent) and a regular GET request
in the client browser and handle them at the same time - in parallel.
The funny thing is that the behaviour of the implementation I created
depends on the existence of Global.asax in the Web application.
Here is the source of the page that handles the regular GET...
|
by: David Colliver |
last post by:
Hi,
using c#, 1.1
I know that we are not supposed to use global variables etc. in c#
I am having a problem, but not sure how to resolve. I did have another post
here, but may have over confused things, so I will start afresh.
An example of what I want to do...
|
by: weaknessforcats |
last post by:
C++: The Case Against Global Variables
Summary
This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition.
The opinions expressed in this article are those of the author alone although many have...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |