Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6798979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:47:39+00:00 2026-05-26T18:47:39+00:00

I’m working with .Net using VB and have just finished a website project and

  • 0

I’m working with .Net using VB and have just finished a website project and I’m getting ready to roll it out…but as I go through a final cleanup/walkthrough I’ve noticed that I currently have used a Public Shared Function 62 times and a Public Shared Sub 14 times, as well as a couple of Public Shared properties.

This is an area I’ve just never been entirely clear on and want to optimize my code properly.

A lot of articles I read seem to indicate that a Public Shared just makes it easier to access a function or sub without creating an instance of it first.

But then other places I read talk about whether this is Shared amongst users on the site.

This is where I’m unsure/confused. If 2 users are on at the same time and they both call the same Public Shared Function or Sub, can things cross over?

Do variables/properties work the same or differently? For instance if I’m storing a user object as a Public Shared Property is that limited to this user only, or will all users be able to access it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:47:40+00:00Added an answer on May 26, 2026 at 6:47 pm

    If you could only pick one, then rerun would be right. But there’s a reason shared exists and it’s best to understand it so you can use it appropriately.

    Let’s say you have a function that just returns all the records in a database, then that would be fine to put in a shared class. And let’s say this function has a parameter that let’s you specify one record you want to return. In this case you’re still safe because each call to the function will add another frame to the stack and track the variables for that frame separately.

    However, if you start working with a class member variable within your function then that’s where you can run into trouble. Let’s say your class uses a member variable that contains the number of rows per page to display. Each time a user changes their preference it will affect all users.

    So, I hope that clears it up for you a bit.

    Edit: In repose to your question…

    Consider the MessageBox class. As you know you do not have to create an instance of it to use its methods. And if two calls are simultaneously made to its Show(string text) method, you don’t have to worry about the second call overwriting the message the first passed because each call to the method maintains its own set of variables.

    However, consider the following class:

    public static class MyMessageBox
    {
        public static string Message { get; set; }
    
        public static void Show() 
        {
            MessageBox.Show(MyMessageBox.Message);
        }
    }
    

    Notice a few things about this class:
    1) Show has to access the Message property through a reference to the static class MyMessageBox. It can’t reference it as ‘this.Message’ because there is no actual instance of the class and therefore no such thing as ‘this’.

    2) Because this is a static class, all properties/fields must be declared as static. However, don’t misunderstand that you can also have a non-static class with static variables and methods. Functionally, making your class static doesn’t change a darned thing about the way your code behaves… it only causes the compiler to enforce certain rules in your class.

    Making a method static allows you to be able to call it as MyClass.SomeMethod() instead of instanceOfMyClass.SomeMethod(). This is only a difference in syntax. In reality, all methods are always static (i.e. there are never multiple instances of your method code… it’s just in one place. It’s the variables that there are instantiated.). In addition to the difference in syntax, making a method static also enforces rules that keep you from referencing any non-static properties/fields which makes sense since you aren’t calling it from an actual instance of your object.

    3) Most importantly, notice that this would be a horrible way to design this class. If two calls are made to the class, it’s possible that one person could set the Message property to “Hello” and someone else could then set it to “World” before the first person displayed their message. Then each person calls the Show() method and you get two message boxes that say “World”.

    There are times when this kind of design is needed, and so you have to uses multi-threading techniques to make subsequent callers wait in line to use a particular resource. But for something as simple as this that would obviously be ridiculous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I am trying to loop through a bunch of documents I have to put
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.