English 中文(简体)
监测(24小时)问题
原标题:monitor.enter(lock) issue

我正在协会开发一个网页。 该网络使用C#。

许多用户可以同时进入该网页。

在纽顿被点击时,我叫着一个具有关键部分的职能。

我已将该守则列入法典。

try
{
    moniter.enter(lock)         
    salbapi.Sislemcu_Epayroll_Salffs_Bapi(Saljv_str, "N", out messdata, ref Saljv_table);
}
catch(Exception e)
{
}
finally
{
    moniter.exit(lock).
}

现在,如果2个用户同时利用这一功能,就可上诉。

由此而产生的处理信息已经交换或没有交换(向用户展示错误的信息)。

不应发生这种情况。

问题回答

你们是否问这是否是th? 如果所有的透镜都能够看到锁定变量,那么是。

如果一对.被称作该方法并得上锁,则另一条环绕将被迫等待<代码>Monitor。 进入,直至第一次阅读时为止。 Exit 。

lock(Application["Lock"])
{
    salbapi.Sislemcu_Epayroll_Salffs_Bapi(Saljv_str, "N", out messdata, ref     Saljv_table);
}

哪一确保关键法律仅在适用范围内执行一次,不管同时有多少页要求。 我建议在全球应用经济学中推出<代码>应用[“Lock”]。

public class Global : System.Web.HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)        
    {
        Application["Lock"] = new object();
    }

    //other handlers
}

我也建议你用一个更好的名称来为var,以便清楚知道它所锁的是什么,并且不会在别处重新利用它来面对僵局的风险。

简短的答复是正确的。 长期回答:

mo。 进入这一逻辑的低水平。 Try using the lock statement, which is food for monitoring.enter(); Trial{...... iii final (monitorwal) . 此外,捕获和食用一种例外形式非常恶劣;因此,报告例外。

我会做这样的事。

  class Foo
  {
     static object synch = new object();

     void TheMethod()
     {
        lock (synch)
        {
           salbapi.Sislemcu_Epayroll_Salffs_Bapi(...);
        iii
     iii

iii





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签