public static T WrapReceive <T>(BlockingReceive <T> b, QueueEmpty qe, object o, MSyncVarOp mop, String instrMethod) { return(SimpleWrap <T>( delegate(ClrSyncManager manager) { T ret; while (true) { manager.SetMethodInfo(instrMethod); manager.SyncVarAccess(o, mop); try { if (qe()) { manager.LocalBacktrack(); continue; } ret = b(); } catch (Exception e) { manager.CommitSyncVarAccess(); throw e; } manager.CommitSyncVarAccess(); break; } ; return ret; }, delegate() { return b(); })); }
/// <summary> /// Fires the OnQueueEmpty callback and sets the minimum time that it /// can be called again /// </summary> /// <param name="o">Throttle categories to fire the callback for, /// stored as an object to match the WaitCallback delegate /// signature</param> private void FireQueueEmpty(object o) { // int start = Environment.TickCount & Int32.MaxValue; // const int MIN_CALLBACK_MS = 30; // if (m_udpServer.IsRunningOutbound) // { ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o; QueueEmpty callback = OnQueueEmpty; if (callback != null) { // if (m_udpServer.IsRunningOutbound) // { try { callback(categories); } catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); } // } } // } // m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; // if (m_nextOnQueueEmpty == 0) // m_nextOnQueueEmpty = 1; // } m_isQueueEmptyRunning = false; }
/// <summary> /// Fires the OnQueueEmpty callback and sets the minimum time that it /// can be called again /// </summary> /// <param name="o">Throttle categories to fire the callback for, /// stored as an object to match the WaitCallback delegate /// signature</param> private void FireQueueEmpty(object o) { ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o; QueueEmpty callback = OnQueueEmpty; if (callback != null) { try { callback(categories); } catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); } } m_isQueueEmptyRunning = false; }
/// <summary> /// Does an early check to see if this queue empty callback is already /// running, then asynchronously firing the event /// </summary> /// <param name="categories">Throttle categories to fire the callback for</param> private void BeginFireQueueEmpty(ThrottleOutPacketTypeFlags categories) { if (!QueueEmptyRunning && HasUpdates(categories) && OnQueueEmpty != null) { double start = Util.GetTimeStampMS(); if (start < m_nextOnQueueEmpty) { return; } QueueEmptyRunning = true; m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; // Asynchronously run the callback if (m_udpServer.OqrEngine.IsRunning) { LLUDPClient udpcli = this; ThrottleOutPacketTypeFlags cats = categories; Action <LLUDPClient, ThrottleOutPacketTypeFlags> act = delegate { QueueEmpty callback = udpcli.OnQueueEmpty; if (callback != null) { try { callback(cats); } catch { } if (callback != null) { udpcli.QueueEmptyRunning = false; } } udpcli = null; callback = null; }; m_udpServer.OqrEngine.QueueJob(AgentID.ToString(), () => act(udpcli, cats)); } else { Util.FireAndForget(FireQueueEmpty, categories, "LLUDPClient.BeginFireQueueEmpty"); } } }
#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(); }
/// <summary> /// Fires the OnQueueEmpty callback and sets the minimum time that it /// can be called again /// </summary> /// <param name="o">Throttle categories to fire the callback for, /// stored as an object to match the WaitCallback delegate /// signature</param> private void FireQueueEmpty(object o) { const int MIN_CALLBACK_MS = 30; ThrottleOutPacketTypeFlags categories = (ThrottleOutPacketTypeFlags)o; QueueEmpty callback = OnQueueEmpty; int start = Environment.TickCount & Int32.MaxValue; if (callback != null) { try { callback(categories); } catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty(" + categories + ") threw an exception: " + e.Message, e); } } m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; if (m_nextOnQueueEmpty == 0) m_nextOnQueueEmpty = 1; }
/// <summary> /// Fires the OnQueueEmpty callback and sets the minimum time that it /// can be called again /// </summary> /// <param name="o">Throttle categories to fire the callback for, /// stored as an object to match the WaitCallback delegate /// signature</param> private void FireQueueEmpty(object o) { const int MIN_CALLBACK_MS = 30; QueueEmpty callback = OnQueueEmpty; int start = Environment.TickCount & Int32.MaxValue; if (callback != null) { try { callback(); } catch (Exception e) { m_log.Error("[LLUDPCLIENT]: OnQueueEmpty() threw an exception: " + e.Message, e); } } m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; if (m_nextOnQueueEmpty == 0) { m_nextOnQueueEmpty = 1; } }
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(); }
/// <summary> /// Fires the OnQueueEmpty callback and sets the minimum time that it /// can be called again /// </summary> /// <param name="o"> /// Throttle categories to fire the callback for, /// stored as an object to match the WaitCallback delegate /// signature /// </param> private void FireQueueEmpty(object o) { const int MIN_CALLBACK_MS = 30; QueueEmpty callback = OnQueueEmpty; int start = Util.EnvironmentTickCount(); if (callback != null) { try { callback(o); } catch (Exception e) { MainConsole.Instance.ErrorFormat("[LLUDPCLIENT]: OnQueueEmpty() threw an exception: {0}", e.ToString()); } } m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; }
/// <summary> /// Fires the OnQueueEmpty callback and sets the minimum time that it /// can be called again /// </summary> /// <param name = "o">Throttle categories to fire the callback for, /// stored as an object to match the WaitCallback delegate /// signature</param> private void FireQueueEmpty(object o) { const int MIN_CALLBACK_MS = 30; QueueEmpty callback = OnQueueEmpty; int start = Util.EnvironmentTickCount(); if (callback != null) { try { callback(o); } catch (Exception e) { MainConsole.Instance.Error("[LLUDPCLIENT]: OnQueueEmpty() threw an exception: " + e.Message, e); } } m_nextOnQueueEmpty = start + MIN_CALLBACK_MS; // if (m_nextOnQueueEmpty == 0) // m_nextOnQueueEmpty = 1; }
private void QueueEmpty_Received(QueueEmpty empty) { Console.WriteLine ("[Downloader] QueueEmpty"); }
public void OnQueueEmpty(object sender, QueueEmptyEventArgs args) { QueueEmpty.Invoke(sender, args); }
private void FireQueueEmptyEvent() { QueueEmpty?.Invoke(this); }
private void OnQueueEmpty(EventArgs eventArgs) { QueueEmpty?.Invoke(this, eventArgs); }
private void QueueEmpty_Received(QueueEmpty empty) { Console.WriteLine("[Downloader] QueueEmpty"); }