Esempio n. 1
0
#pragma warning disable 4014
        private void SendVoiceTask(CancellationToken token)
        {
            VoiceSendThread = new Thread(() =>
            {
                while (!token.IsCancellationRequested)
                {
                    if (!voiceToSend.IsEmpty)
                    {
                        QueueEmptyEventTriggered = false;
                        try
                        {
                            SendVoiceAsync(token);
                        }
                        catch (Exception ex)
                        {
                            VoiceDebugLogger.Log(ex.Message, MessageLevel.Error);
                        }
                    }
                    else
                    {
#if NETFX4_5
                        //await Task.Delay(1000).ConfigureAwait(false);
                        Thread.Sleep(1000);
#else
                        Thread.Sleep(1000);
#endif
                    }
                    if (___sequence > 0 || ___timestamp > 0)
                    {
                        if (voiceToSend.IsEmpty)
                        {
                            //reset these
                            ___sequence  = 0;
                            ___timestamp = 0;
                            if (!QueueEmptyEventTriggered)
                            {
                                QueueEmpty?.Invoke(this, new EventArgs());
                                QueueEmptyEventTriggered = true;
                            }
                        }
                    }
                }
            });
            VoiceSendThread.Start();
        }
        private async Task WriteLines()
        {
            while (Queue.Count != 0)
            {
                try
                {
                    _semaphore.WaitOne();
                    await CheckFileInitialization();

                    using (IRandomAccessStream stream = await _storageFile.OpenAsync(FileAccessMode.ReadWrite, StorageOpenOptions.AllowOnlyReaders))
                    {
                        stream.Seek(stream.Size);
                        for (int i = 0; i < 10 && Queue.Count != 0; i++)
                        {
                            if (!string.IsNullOrEmpty(Queue[0]))
                            {
                                await stream.WriteAsync(CryptographicBuffer.ConvertStringToBinary(Queue[0], BinaryStringEncoding.Utf8));

                                await stream.WriteAsync(LINE_END);

                                await stream.FlushAsync();
                            }
                            Queue.RemoveAt(0);
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.Error("Error while writing", e);
                }
                finally
                {
                    Logger.Trace("Write end");
                    _semaphore.Release();
                }
            }

            _runningTask = null;
            QueueEmpty?.Invoke();
        }
Esempio n. 3
0
 public void OnQueueEmpty(object sender, QueueEmptyEventArgs args)
 {
     QueueEmpty.Invoke(sender, args);
 }
Esempio n. 4
0
 private void FireQueueEmptyEvent()
 {
     QueueEmpty?.Invoke(this);
 }
Esempio n. 5
0
 private void OnQueueEmpty(EventArgs eventArgs)
 {
     QueueEmpty?.Invoke(this, eventArgs);
 }