如何prevent多个用户同时加入一个项目到SharePoint列表 [英] How to prevent multiple users from adding an item to a Sharepoint list simultaneously

查看:86
本文介绍了如何prevent多个用户同时加入一个项目到SharePoint列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是简单的形式,让人们注册一个事件。他们的详细资料保存到SharePoint列表。我有一个人配额谁可以注册一个事件(比如100人)。

I am using a simple form to allow people to sign up for an event. Their details are saved to a Sharepoint list. I have a quota of people who can sign up for an event (say 100 people).

我怎样才能prevent第100和第101人,从报名的同时,导致配额检查,允许101人​​报名(因为100人不在列表中还没有)?

How can I prevent the 100th and the 101st person from signing up concurrently, causing the quota check to allow the 101st person to sign up (because the 100th person isn't in the list yet)?

推荐答案

代替 ItemAdding code里面的 锁定语句,以确保只有一次可以输入code中的关键部分螺纹:

Place the ItemAdding code inside a lock statement to make sure that only one thread at a time can enter the critical section of code:

private Object _lock = new Object();

public override void ItemAdding(SPItemEventProperties properties)
{
    lock(_lock)
    {
        // check number of the list items and cancel the event if necessary
    }
}


我想出了这个主意的一个农场有多个WFES一个解决方案 - 共享资源(排在伪code以上的表)中的项目添加到列表中的时间被锁定:


I came up with this idea of a solution for a farm with multiple WFEs - a shared resource (a row in a table in pseudo-code above) gets locked during the time the item is added to the list:

private Object _lock = new Object();

public override void ItemAdding(SPItemEventProperties properties)
{
    try
    {
        // 1. begin a SQL Server transaction
        // 2. UPDATE dbo.SEMAPHORE
        //    SET STATUS = 'Busy'
        //    WHERE PROCESS = 'EventSignup'

        lock(_lock)
        {
            // 3. check number of the list items and cancel the event if necessary
        }
    }
    finally
    {
        // 4. UPDATE dbo.SEMAPHORE
        //    SET STATUS = ''
        //    WHERE PROCESS = 'EventSignup'
        // 5. commit a SQL Server transaction
    }
}

我离开了锁定语句,因为我不知道如果相同的前端服务器尝试添加的项目#会发生什么100和#101 - 将在交易锁定该行还是会不会因为到SQL Server相同的连接将被使用?

I left the lock statement because I'm not sure what will happen if the same front-end server tries to add the item #100 and #101 - will the transaction lock the row or will it not because the same connection to SQL Server will be used?

这篇关于如何prevent多个用户同时加入一个项目到SharePoint列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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