简体   繁体   English

多线程CSLA.NET

[英]Multithreading CSLA.NET

I have a program that we'd like to multi-thread at a certain point. 我有一个程序,我们希望在某个时候进行多线程处理。 We're using CSLA for our business rules. 我们将CSLA用于我们的业务规则。 At a one location of our program we are iterating over a BusinessList object and running some sanity checks against the data one row at a time. 在程序的一个位置,我们遍历一个BusinessList对象,并一次对数据进行一些完整性检查。 When we up the row count to about 10k rows it takes some time to run the process (about a minute). 当我们将行数增加到大约1万行时,将需要一些时间来运行该过程(大约一分钟)。 Naturally this sounds like a perfect place to use a bit of TPL and make this multi-threaded. 自然,这听起来像是使用一些TPL并使其成为多线程的理想场所。

I've done a fair amount of multithreaded work through the years, so I understand the pitfalls of switching from single to multithreaded code. 这些年来,我已经做了大量的多线程工作,因此我了解了从单线程代码切换到多线程代码的陷阱。 I was surprised to find that the code bombed within the CSLA routines themselves. 我很惊讶地发现该代码在CSLA例程本身中遭到了轰炸。 It seems to be related to the code behind the CSLA PropertyInfo classes. 它似乎与CSLA PropertyInfo类背后的代码有关。

All of our business object properties are defined like this: 我们所有的业务对象属性都定义如下:

    public static readonly PropertyInfo<string> MyTextProperty = RegisterProperty<string>(c => c.MyText); 
public string MyText { 
get { return GetProperty(MyTextProperty); } 
set { SetProperty(MyTextProperty, value); } 
}

Is there something I need to know about multithreading and CSLA? 我需要了解多线程和CSLA吗? Are there any caveats that aren't found in any written documentation (I haven't found anything as of yet). 是否有任何书面文档中未发现的警告(到目前为止,我还没有发现任何警告)。

--EDIT--- - 编辑 - -

BTW: the way I implemented my multithreading via throwing all the rows into a ConcurrentBag and then spawning 5 or so tasks that just grab objects from the bag till the bag is empty. 顺便说一句:我实现多线程的方式是将所有行都扔到ConcurrentBag中,然后产生5个左右的任务,这些任务只是从袋子中抓取对象直到袋子空了。 So I don't think the problem is in my code. 因此,我认为问题不在我的代码中。

As you've discovered, the CSLA.NET framework is not thread-safe. 如您所知,CSLA.NET框架不是线程安全的。

To solve your particular problem, I would make use of the Wintellect Power Threading library; 为了解决您的特定问题,我将使用Wintellect Power Threading库。 either the AsyncEnumerator / SyncGate combo or the ReaderWriterGate on its own. AsyncEnumerator / SyncGate组合或ReaderWriterGate本身。

The Power Threading library will allow you queue 'read' and 'write' requests to a shared resource (your CSLA.NET collection). Power Threading库将允许您将“读取”和“写入”请求排队到共享资源(您的CSLA.NET集合)中。 At one moment in time, only a single 'write' request will be allowed access to the shared resource, all without thread-blocking the queued 'read' or 'write' requests. 在某一时刻,只允许单个“写”请求访问共享资源,而所有请求都不会线程阻塞排队的“读”或“写”请求。 Its very clever and super handy for safely accessing shared resources from multiple threads. 它非常聪明,非常方便,可以安全地从多个线程访问共享资源。 You can spin up as many threads as you wish and the Power Threading library will synchronise the access to your CSLA.NET collection. 您可以根据需要增加任意数量的线程,Power Threading库将同步对CSLA.NET集合的访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM