/// </summary>
public void AddMetadata(string key, string value)
{
- lock (MyLock)
+ lock (this)
{
_metadata = _metadata ?? new Dictionary<string, string>();
_metadata.Add(key, value);
internal abstract void WritePayload(float intervalSec, int pollingIntervalMillisec);
- // arbitrarily we use name as the lock object.
- internal object MyLock { get { return Name; } }
-
internal void ReportOutOfBandMessage(string message)
{
EventSource.ReportOutOfBandMessage(message, true);
internal string GetMetadataString()
{
+ Debug.Assert(Monitor.IsEntered(this));
+
if (_metadata == null)
{
return "";
internal void OnMetricWritten(double value)
{
- Debug.Assert(Monitor.IsEntered(MyLock));
+ Debug.Assert(Monitor.IsEntered(this));
_sum += value;
_sumSquared += value * value;
if (value > _max)
internal override void WritePayload(float intervalSec, int pollingIntervalMillisec)
{
- lock (MyLock)
+ lock (this)
{
Flush();
CounterPayload payload = new CounterPayload();
private void ResetStatistics()
{
- Debug.Assert(Monitor.IsEntered(MyLock));
+ Debug.Assert(Monitor.IsEntered(this));
_count = 0;
_sum = 0;
_sumSquared = 0;
{
// It is possible that two threads both think the buffer is full, but only one get to actually flush it, the other
// will eventually enter this code path and potentially calling Flushing on a buffer that is not full, and that's okay too.
- lock (MyLock) // Lock the counter
+ lock (this) // Lock the counter
Flush();
i = 0;
}
protected void Flush()
{
- Debug.Assert(Monitor.IsEntered(MyLock));
+ Debug.Assert(Monitor.IsEntered(this));
for (int i = 0; i < _bufferedValues.Length; i++)
{
var value = Interlocked.Exchange(ref _bufferedValues[i], UnusedBufferSlotValue);
/// <param name="increment">The value to increment by.</param>
public void Increment(double increment = 1)
{
- lock (MyLock)
+ lock (this)
{
_increment += increment;
}
internal override void WritePayload(float intervalSec, int pollingIntervalMillisec)
{
- lock (MyLock) // Lock the counter
+ lock (this) // Lock the counter
{
IncrementingCounterPayload payload = new IncrementingCounterPayload();
payload.Name = Name;
{
try
{
- lock (MyLock)
+ lock (this)
{
_increment = _totalValueProvider();
}
internal override void WritePayload(float intervalSec, int pollingIntervalMillisec)
{
UpdateMetric();
- lock (MyLock) // Lock the counter
+ lock (this) // Lock the counter
{
IncrementingCounterPayload payload = new IncrementingCounterPayload();
payload.Name = Name;