Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多线程操作契约中的同步_C#_Multithreading_Wcf_Thread Safety_Task - Fatal编程技术网

C# 多线程操作契约中的同步

C# 多线程操作契约中的同步,c#,multithreading,wcf,thread-safety,task,C#,Multithreading,Wcf,Thread Safety,Task,下面的操作契约构造并返回一个称为ObjectGraph的反序列化数据结构。这是通过 步骤(a)使用登录用户检索对象id。这确保没有两个用户获得相同的对象id 步骤(b)使用对象id(来自步骤a)加载序列化对象图 在此阶段,使用lock在同步块内执行步骤a和b。这正如预期的那样有效。但是,出于性能考虑,我现在想将步骤a和b分开,因为步骤b比步骤a花费的时间更长,因此客户端很容易排队 是否可以在不丢失同步访问的情况下进行拆分?如果是,有人知道怎么做吗 [ErrorBehavior(typeof(

下面的操作契约构造并返回一个称为
ObjectGraph
的反序列化数据结构。这是通过

  • 步骤(a)使用登录用户检索对象id。这确保没有两个用户获得相同的对象id

  • 步骤(b)使用对象id(来自步骤a)加载序列化对象图

在此阶段,使用
lock
在同步块内执行步骤ab。这正如预期的那样有效。但是,出于性能考虑,我现在想将步骤ab分开,因为步骤b比步骤a花费的时间更长,因此客户端很容易排队

是否可以在不丢失同步访问的情况下进行拆分?如果是,有人知道怎么做吗

[ErrorBehavior(typeof(ErrorHandler))]
[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple, InstanceContextMode=InstanceContextMode.PerCall)]
public class ServiceImp : IService
{
    private static object _lockOb = new object();
    //ObjectGraph is a custom data structure.
    public ObjectGraph GetObject(Guid IdUser)
    {
        lock(_lockOb) //This is to ensure that no two or more client execute below logic at any point in time.
        {
            //GetId method returns object id from database.
            var id=GetId(); 

            //LoadObjectGraphFromDatabase accept object id, read serialized data from database and finally returns a de-serialized ObjectGraph object.
            var graph=LoadObjectGraphFromDatabase(id) 
            return graph;
        }
    }
}

什么在阻止另一个进程改变数据库中Id为的图形?这样的问题可能更适合。如何拆分A和b?b取决于a-它需要从a返回的id。还有,为什么你要在方法中乱搞锁,让WCF通过并发模式来管理它。@MitchWheat,如果我没有弄错的话,一旦分派了对象id,我就会切换锁标志(db列)。@Nair:这对我来说毫无意义。