473,419 Members | 2,065 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,419 software developers and data experts.

global function without using object?

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
Nov 19 '05 #1
2 1644
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*******@yahoo.com> wrote in message
news:25*************************@posting.google.co m...
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

Nov 19 '05 #2
"Henry" <ea*******@yahoo.com> wrote in message
news:25*************************@posting.google.co m...
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

"beVeryCareful" 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
Nov 19 '05 #3

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

Similar topics

88
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...
4
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(); ...
3
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...
8
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...
7
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...
16
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...
0
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...
23
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...
1
weaknessforcats
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
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,...

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.