Click here to Skip to main content
15,915,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a web application using SignalR. Upon creation, I want to validate the pages with the custom authentication using UserName and Password.
When the user opens the page which is created using SignalR to fetch realtime data, an instance of the page will be created.
When the user opens the same page in some other tab of the browser, the new instance will be created. Hence, the same user will have 2 instance of the page.

I want to have instance created for individual users. But not multiple instance for single user.
The Question is, I do not want the user to occupy 2 instance of the page. Could anyone help me out with this?

When I go through online blogs, they direct me to use Singleton. Pleas advice me if Singleton is the answer for this problem as well.

What I have tried:

I have tried to create the webform using SignalR to fetch realtime data. But I get multiple instance created for same user if the page is opened in multiple tabs of the browser.

I haven't tried with Singleton.
Posted
Updated 8-Nov-16 2:05am
v2

1 solution

C#
public sealed class Singleton
{
    private static Singleton instance = null;
    private static readonly object padlock = new object();

    Singleton()
    {
    }

    public static Singleton Instance
    {
        get
        {
            lock (padlock)
            {
                if (instance == null)
                {
                    instance = new Singleton();
                }
                return instance;
            }
        }
    }
}
 
Share this answer
 
Comments
Giridharan_BE 10-Nov-16 1:33am    
This doesn't seem to work. Could you please explain how this works or do you have any other idea to implement this other than singleton?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900