直接做过一个排队拿号的,用的锁,你可以把查询剩余票数的代码lock住。但是效率不是很高。

解决方案 »

  1.   

    服务器应该不是同时响应的,就像cup的多任务处理一样,只有一个cpu可以同时运行多个程序。
      

  2.   

    SQL Transaction啊,买本sql 的书看看吧。
      

  3.   

    如果是sqlserver 数据库,回用到里面事务
    类似下面begin tran 
    begin try 
    insert into 我的数据库.dbo.B()
    select *
    from A where A.Record_ID = (select Record_ID from inserted)
    update tb set A=’XX’ where ID=’1’
    commit
    end try
    begin catch
    rollback
    end catch
      

  4.   

    安要求指点编号订票比如这里是5,如果谁抢先输入对了就得到了订票,否则票已订空
    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == (Char)Keys.Return) //如果按下回车键
                {
                    if (textBox1.Text.Length > 5) //如果位数大于5
                    {
                        textBox1.Text = textBox1.Text.Substring(0, 5); //获取前5位数
                    }//CodeGo.net/
                    else
                    {
                        int j = 5 - textBox1.Text.Length; //确定增加的位数
                        for (int i = 0; i < j; i++)
                        {
                            textBox1.Text = "0" + textBox1.Text;
                        }
                    }
                }
            }