如何拥有webform的单个实例 [英] How to have single instance of webform

查看:76
本文介绍了如何拥有webform的单个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SignalR创建一个Web应用程序。创建后,我想使用UserName和Password自定义身份验证页面。

当用户打开使用SignalR创建的页面来获取实时数据时,将创建一个页面实例。

当用户在某些页面打开同一页面时浏览器的其他选项卡将创建新实例。因此,同一个用户将有2个页面实例。



我想为个人用户创建实例。但不是单个用户的多个实例。

问题是,我不希望用户占用页面的2个实例。任何人都可以帮我解决这个问题吗?



当我浏览在线博客时,他们会指导我使用Singleton。如果Singleton也是这个问题的答案,请告诉我。



我尝试过:



我尝试使用SignalR创建webform以获取实时数据。但是如果在浏览器的多个选项卡中打开页面,我会为同一个用户创建多个实例。



我没有尝试使用Singleton。

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.

推荐答案

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;
            }
        }
    }
}


这篇关于如何拥有webform的单个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆