I have a question of understanding. Which is the better option in terms of safety and performance?
private ConcurrentDictionary<string, ProfitTarget> chartTraderTP;
if (chartTraderTP.ContainsKey(orderId))
{
//Store values for later use in Mouse Events
chartTraderTP[orderId].OrderLabelRectText = rectTextOrderLabelTP;
//We can draw the Rectangle based on the TextLayout used above
if (!chartTraderTP[orderId].IsMovingOrder
&& (ChartTraderDisplayStyle == ChartTraderDisplayStyle.Own
|| ChartTraderDisplayStyle == ChartTraderDisplayStyle.Both))
{
RenderTarget.FillRectangle(rectTextOrderLabelTP, tpAreaBrushDx);
RenderTarget.DrawRectangle(rectTextOrderLabelTP, tpOutlineBrushDx,
LabelOutlineWidthTP);
RenderTarget.DrawTextLayout(vectText, tpTextLayout, tpTextBrushDx,
SharpDX.Direct2D1.DrawTextOptions.NoSnap);
}
}
or
private ConcurrentDictionary<string, ProfitTarget> chartTraderTP;
//Store values for later use in Mouse Events
if (chartTraderTP.ContainsKey(orderId))
{
chartTraderTP[orderId].OrderLabelRectText = rectTextOrderLabelTP;
}
//We can draw the Rectangle based on the TextLayout used above
if (chartTraderTP.ContainsKey(orderId) && !chartTraderTP[orderId].IsMovingOrder
&& (ChartTraderDisplayStyle == ChartTraderDisplayStyle.Own
|| ChartTraderDisplayStyle == ChartTraderDisplayStyle.Both))
{
RenderTarget.FillRectangle(rectTextOrderLabelTP, tpAreaBrushDx);
RenderTarget.DrawRectangle(rectTextOrderLabelTP, tpOutlineBrushDx,
LabelOutlineWidthTP);
RenderTarget.DrawTextLayout(vectText, tpTextLayout, tpTextBrushDx,
SharpDX.Direct2D1.DrawTextOptions.NoSnap);
}
The code is executed very often, and I would like to make the access as fast as possible but still threadsafe.