private void StartRecordingAction()
{
lock (ServiceLocator.SoundRecorderService)
{
if (IsRecording)
{
ServiceLocator.SoundRecorderService.StopRecording();
ServiceLocator.SoundRecorderService.StopPlayingRecordedSound();
if (ServiceLocator.SoundRecorderService.State == SoundRecorderState.Recording)
ServiceLocator.SoundRecorderService.StopRecording();
//_recordTimeUpdateTaskCancellationToken.Cancel();
//_recordTimeUpdateTask.Abort();
RecordingExists = true;
}
else
{
IsPlaying = false;
RecordingExists = false;
ServiceLocator.SoundRecorderService.StartRecording();
_recorderStartTime = DateTime.UtcNow;
//_recordTimeUpdateTaskCancellationToken = new CancellationTokenSource();
_recordTimeUpdateTask = new Task(delegate()
{
try
{
while (ServiceLocator.SoundRecorderService.State != SoundRecorderState.StoppingRecording &&
ServiceLocator.SoundRecorderService.State != SoundRecorderState.NoAction)
{
_recorderTimeGoneBy = DateTime.UtcNow - _recorderStartTime;
ServiceLocator.DispatcherService.RunOnMainThread(() =>
{
RecordingTime = _recorderTimeGoneBy.TotalSeconds;
});
Task.Delay(45).Wait();
//Thread.Sleep(45);
}
}
catch
{
/* Nothing here */
}
}
);
_recordTimeUpdateTask.Start();
}
}
IsRecording = !IsRecording;
}