Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Add block thread constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
William Li committed Jul 26, 2017
1 parent 6541a16 commit c859035
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/dotnet/Telemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,28 @@ public Telemetry(IFirstTimeUseNoticeSentinel sentinel, string sessionId)
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry());
}

public Telemetry(IFirstTimeUseNoticeSentinel sentinel, string sessionId, bool blockThreadInitialization)
{
Enabled = !Env.GetEnvironmentVariableAsBool(TelemetryOptout) && PermissionExists(sentinel);

if (!Enabled)
{
return;
}

// Store the session ID in a static field so that it can be reused
CurrentSessionId = sessionId ?? Guid.NewGuid().ToString();

if (blockThreadInitialization)
{
InitializeTelemetry();
}
else
{
_trackEventTask = Task.Factory.StartNew(() => InitializeTelemetry());
}
}

private bool PermissionExists(IFirstTimeUseNoticeSentinel sentinel)
{
if (sentinel == null)
Expand Down Expand Up @@ -126,9 +148,9 @@ private void TrackEventTask(string eventName, IDictionary<string, string> proper
_client.TrackEvent(eventName, eventProperties, eventMeasurements);
_client.Flush();
}
catch (Exception)
catch (Exception e)
{
Debug.Fail("Exception during TrackEventTask");
Debug.Fail(e.ToString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal ThreadBlockingTelemetry()
{
var sessionId =
Environment.GetEnvironmentVariable(TelemetrySessionIdEnvironmentVariableName);
telemetry = new Telemetry(new NoOpFirstTimeUseNoticeSentinel(), sessionId);
telemetry = new Telemetry(new NoOpFirstTimeUseNoticeSentinel(), sessionId, blockThreadInitialization: true);
}
public bool Enabled => telemetry.Enabled;

Expand Down

0 comments on commit c859035

Please sign in to comment.