English 中文(简体)
B. 关于使用并行语文的一些问题
原标题:some questions around the use of ConcurrentDictionary

我目前正在撰写一份C#申请。 我是新颖的,是使用一名同步理论家,因此对其表面安全有一些问题。 首先,这是我所说的话:

    /// <summary>
    /// A dictionary of all the tasks scheduled
    /// </summary>
    private ConcurrentDictionary<string, ITask> tasks;

我在我的班子里立即这样做,并利用它追踪我执行ITask的所有物体。 我希望确保我的组成能够在多面的环境下正确开展工作。

如果多管齐下,要把同时存放的物品数目计算在内,我是否需要锁定?

如果我想从独裁者那里获得一个特别关键人物,拿到该钥匙的标的,并把它称作一种方法,那么我是否需要打锁? 指称:

    /// <summary>
    /// Runs a specific task.
    /// </summary>
    /// <param name="name">Task name.</param>
    public void Run(string name)
    {
        lock (this.syncObject)
        {
            var task = this.tasks[name] as ITask;
            if (task != null)
            {
                task.Execute();
            }
        }
    }

牢记多个线索,可以称之为“跟踪方法”,即“信息技术”。 我的目标是使一切都变得安全,尽可能发挥效力。

最佳回答
问题回答

混合剂的所有方法都能够安全地从多个深层中调取。

它并不保证你方案的其他部分不需要同步,因为你可能需要同时使用锁,以便接触其他物体/多目标。

I.e. 阁下的样本代码为完成任务和执行任务提供了锁。 这表明了在原子接触多个物体方面的锁定。

Side note: you should review your lock for task.Execute() as it prohibits other threads to execute task in parallel. It may be what you want to achieve, but in this case using ConcurrentDictionary may be overkill.





相关问题
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!