/// <summary> /// 指定对象标识,超时时长(秒为单位),超时执行回调,加入到超时检测字典中 /// </summary> /// <param name="objectKey"></param> /// <param name="timeoutSeconds"></param> /// <param name="callback"></param> /// <param name="context"></param> /// <returns></returns> public long AddTimeoutTask(T objectKey, int timeoutSeconds, TimeoutCallback <T> callback, String context) { TimeoutTask <T> task = new TimeoutTask <T>(); task.ObjectKey = objectKey; task.TimeoutSeconds = timeoutSeconds; task.Callback = callback; long taskId = GetNextTaskId(); task.TaskId = taskId; task.ExecuteSecondTicks = DateTime.Now.Ticks / 10000000 + timeoutSeconds; task.Context = context; lock (_DictionaryLocker) { // 以任务标识为主键的任务清单 _TaskIdDictionary[taskId] = task; // 以对象标识为主键的任务清单 if (_TaskObjectKeyDictionary.ContainsKey(objectKey)) { _TaskObjectKeyDictionary[objectKey].Add(task); } else { List <TimeoutTask <T> > list = new List <TimeoutTask <T> >(); list.Add(task); _TaskObjectKeyDictionary[objectKey] = list; } } return(taskId); }
protected void Timeout(SSContext context, long timeout, TimeoutCallback callback) { long timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); if (timeout <= 0) { callback(context, timestamp); } else { if (m_totalServiceSession >= Int32.MaxValue) { m_totalServiceSession = 0; } SSTimerNode timerNode = new SSTimerNode(); timerNode.Opaque = m_serviceAddress; timerNode.Session = ++m_totalServiceSession; timerNode.TimeoutTimestamp = timestamp + timeout; SSTimer.GetInstance().Add(timerNode); TimeoutContext timeoutContext = new TimeoutContext(); timeoutContext.Callback = callback; timeoutContext.Context = context; m_timeoutCallbacks.Add(timerNode.Session, timeoutContext); } }
public Timeout(TimeSpan begin, TimeSpan span, IRepeatBehavior repeat, object data, TimeoutCallback callback) { this.begin = begin; this.span = span; this.repeat = repeat; this.data = data; this.callback = callback; }
public bool RemoveTimeoutListener(TimeoutCallback callback, object userData) { TimeoutListener item = new TimeoutListener(); item.SetCallback(callback); item.SetUserData(userData); return(this.m_timeoutListeners.Remove(item)); }
public Timeout(DateTime expires, TimeSpan span, IRepeatBehavior repeat, object data, TimeoutCallback callback) { this.expires = expires; this.span = span; this.repeat = repeat; this.data = data; this.callback = callback; }
// Outro private void PlayCinematicOutro() { _cinematicControllerOutro.PlayCinematic(); float duration = (float)_cinematicControllerOutro.duration; TimeoutCallback onCompleteCallback = OutroCompletedHandler; StartCoroutine(SetTimeout(duration, OutroCompletedHandler)); }
// If forward progress on the script isn't made within this // amount of time (milliseconds), bail public static void Timeout(long duration, TimeoutCallback callback) { // Don't change an existing timeout if (_executionState != ExecutionState.RUNNING) { return; } _pauseTimeout = DateTime.UtcNow.Ticks + (duration * 10000); _executionState = ExecutionState.TIMING_OUT; _timeoutCallback = callback; }
public static bool ExecuteScript() { if (_activeScript == null) { return(false); } if (_executionState == ExecutionState.PAUSED) { if (_pauseTimeout < DateTime.UtcNow.Ticks) { _executionState = ExecutionState.RUNNING; } else { return(true); } } else if (_executionState == ExecutionState.TIMING_OUT) { if (_pauseTimeout < DateTime.UtcNow.Ticks) { if (_timeoutCallback != null) { if (_timeoutCallback()) { _activeScript.Advance(); ClearTimeout(); } _timeoutCallback = null; } /* If the callback changed the state to running, continue * on. Otherwise, exit. */ if (_executionState != ExecutionState.RUNNING) { _activeScript = null; return(false); } } } if (!_activeScript.ExecuteNext()) { _activeScript = null; return(false); } return(true); }
public bool AddTimeoutListener(TimeoutCallback callback, object userData) { TimeoutListener item = new TimeoutListener(); item.SetCallback(callback); item.SetUserData(userData); if (this.m_timeoutListeners.Contains(item)) { return(false); } this.m_timeoutListeners.Add(item); return(true); }
public static void ConnectSSLAsync(string host, int port, Factory factory, object contextFactory, int timeout, string bindAddress, ConnectedCallback callback, TimeoutCallback timeoutCallback, object state) { TcpClient client = new TcpClient(); IAsyncResult ar = client.BeginConnect(host, port, null, new AsyncConnectState { responseCallback = callback, timeoutCallback = timeoutCallback, client = client, factory = factory, state = state }); ThreadPool.RegisterWaitForSingleObject(ar.AsyncWaitHandle, _ConnectSSL_Callback, ar, timeout, true); }
// Intro private void PlayCinematicIntro() { if (_isDebug) { return; } _cinematicControllerIntro.PlayCinematic(); float duration = (float)_cinematicControllerIntro.duration; TimeoutCallback onCompleteCallback = IntroCompletedHandler; StartCoroutine(SetTimeout(duration, IntroCompletedHandler)); }
private void CheckVolume() { if (_isDebug) { TimeoutCallback onStopPlayingCallback = onStopPlayingHandler; StartCoroutine(Debounced(endGameSilenceDuration, onStopPlayingCallback)); } // Trigger GameOver when user stopped playing music else if (data.micVolumeNormalized > 0.1f) { TimeoutCallback onStopPlayingCallback = onStopPlayingHandler; StartCoroutine(Debounced(endGameSilenceDuration, onStopPlayingCallback)); } }
IEnumerator Debounced(float time, TimeoutCallback Method) { // generate a new id and set it as the latest one Guid guid = Guid.NewGuid(); _latest = guid; // set the denounce duration here yield return(new WaitForSeconds(time)); // check if this call is still the latest one if (_latest == guid) { Method(); } }
/// <param name="id">Id of the state.</param> /// <param name="displayName">Displayname of the state.</param> /// <param name="timeoutSec">Seconds, after the asynchronous task should be aborted.</param> /// <param name="timeoutCallback">Callback to report, that the task was aborted because of a timeout.</param> /// <param name="progressCallback">Callback to report, that the task makes progress.</param> public WuStateAsyncJob(WuStateId id, string displayName, int timeoutSec, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback) : base(id, displayName) { if (timeoutSec < 0) { throw new ArgumentOutOfRangeException(nameof(timeoutSec), "Negative timeout is not allowed."); } if (timeoutSec > int.MaxValue / 1000) { throw new ArgumentOutOfRangeException(nameof(timeoutSec), $"Max timeout is {int.MaxValue / 1000} sec."); } if (timeoutCallback == null) { throw new ArgumentNullException(nameof(timeoutCallback)); } TimeoutSec = timeoutSec; TimeoutCallbackDelegate = timeoutCallback; ProgressChangedCallbackDelegate = progressCallback; }
public WuStateInstalling(IUpdateInstaller uInstaller, IUpdateCollection updates, InstallCompletedCallback completedCallback, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback, int timeoutSec) : base(WuStateId.Installing, "Installing Updates", timeoutSec, timeoutCallback, progressCallback) { if (uInstaller == null) { throw new ArgumentNullException(nameof(uInstaller)); } if (updates == null) { throw new ArgumentNullException(nameof(updates)); } if (completedCallback == null) { throw new ArgumentNullException(nameof(completedCallback)); } _uInstaller = uInstaller; _updates = updates; _completedCallback = completedCallback; }
public static Timeout AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { return AppHost.AddTimeout (timespan, repeat, data, callback); }
public static Timeout AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, TimeoutCallback callback) { return(AddTimeout(timespan, repeat, null, callback)); }
internal ConnectionI(Communicator communicator, IceInternal.Instance instance, IceInternal.ACMMonitor monitor, IceInternal.Transceiver transceiver, IceInternal.Connector connector, IceInternal.EndpointI endpoint, ObjectAdapterI adapter) { _communicator = communicator; _instance = instance; _monitor = monitor; _transceiver = transceiver; _desc = transceiver.ToString(); _type = transceiver.protocol(); _connector = connector; _endpoint = endpoint; _adapter = adapter; InitializationData initData = instance.initializationData(); _logger = initData.logger; // Cached for better performance. _traceLevels = instance.traceLevels(); // Cached for better performance. _timer = instance.timer(); _writeTimeout = new TimeoutCallback(this); _writeTimeoutScheduled = false; _readTimeout = new TimeoutCallback(this); _readTimeoutScheduled = false; _warn = initData.properties.getPropertyAsInt("Ice.Warn.Connections") > 0; _warnUdp = initData.properties.getPropertyAsInt("Ice.Warn.Datagrams") > 0; _cacheBuffers = instance.cacheMessageBuffers() > 0; if(_monitor != null && _monitor.getACM().timeout > 0) { _acmLastActivity = IceInternal.Time.currentMonotonicTimeMillis(); } else { _acmLastActivity = -1; } _nextRequestId = 1; _messageSizeMax = adapter != null ? adapter.messageSizeMax() : instance.messageSizeMax(); _batchRequestQueue = new IceInternal.BatchRequestQueue(instance, _endpoint.datagram()); _readStream = new IceInternal.BasicStream(instance, Util.currentProtocolEncoding); _readHeader = false; _readStreamPos = -1; _writeStream = new IceInternal.BasicStream(instance, Util.currentProtocolEncoding); _writeStreamPos = -1; _dispatchCount = 0; _state = StateNotInitialized; _compressionLevel = initData.properties.getPropertyAsIntWithDefault("Ice.Compression.Level", 1); if(_compressionLevel < 1) { _compressionLevel = 1; } else if(_compressionLevel > 9) { _compressionLevel = 9; } if(adapter != null) { _servantManager = adapter.getServantManager(); } try { if(adapter != null) { _threadPool = adapter.getThreadPool(); } else { _threadPool = instance.clientThreadPool(); } _threadPool.initialize(this); } catch(LocalException) { throw; } catch(System.Exception ex) { throw new SyscallException(ex); } }
public static Timeout AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, TimeoutCallback callback) { return AddTimeout (timespan, repeat, null, callback); }
public static void AddTimeout(TimeSpan timespan, TimeoutCallback callback) { AddTimeout(timespan, RepeatBehavior.Single, null, callback); }
public static void AddTimeout(TimeSpan timespan, object data, TimeoutCallback callback) { AddTimeout(timespan, RepeatBehavior.Single, data, callback); }
internal ConnectionI(Communicator communicator, IceInternal.Instance instance, IceInternal.ConnectionReaper reaper, IceInternal.Transceiver transceiver, IceInternal.Connector connector, IceInternal.EndpointI endpoint, ObjectAdapter adapter) { _communicator = communicator; _instance = instance; _reaper = reaper; InitializationData initData = instance.initializationData(); _transceiver = transceiver; _desc = transceiver.ToString(); _type = transceiver.type(); _connector = connector; _endpoint = endpoint; _adapter = adapter; _dispatcher = initData.dispatcher; // Cached for better performance. _logger = initData.logger; // Cached for better performance. _traceLevels = instance.traceLevels(); // Cached for better performance. _timer = instance.timer(); _writeTimeout = new TimeoutCallback(this); _writeTimeoutScheduled = false; _writeStreamPos = -1; _readTimeout = new TimeoutCallback(this); _readTimeoutScheduled = false; _readStreamPos = -1; _warn = initData.properties.getPropertyAsInt("Ice.Warn.Connections") > 0; _warnUdp = initData.properties.getPropertyAsInt("Ice.Warn.Datagrams") > 0; _cacheBuffers = initData.properties.getPropertyAsIntWithDefault("Ice.CacheMessageBuffers", 1) == 1; _acmAbsoluteTimeoutMillis = 0; _nextRequestId = 1; _batchAutoFlush = initData.properties.getPropertyAsIntWithDefault("Ice.BatchAutoFlush", 1) > 0; _batchStream = new IceInternal.BasicStream(instance, Util.currentProtocolEncoding, _batchAutoFlush); _batchStreamInUse = false; _batchRequestNum = 0; _batchRequestCompress = false; _batchMarker = 0; _readStream = new IceInternal.BasicStream(instance, Util.currentProtocolEncoding); _readHeader = false; _writeStream = new IceInternal.BasicStream(instance, Util.currentProtocolEncoding); _dispatchCount = 0; _state = StateNotInitialized; _compressionLevel = initData.properties.getPropertyAsIntWithDefault("Ice.Compression.Level", 1); if(_compressionLevel < 1) { _compressionLevel = 1; } else if(_compressionLevel > 9) { _compressionLevel = 9; } ObjectAdapterI adapterImpl = _adapter as ObjectAdapterI; if(adapterImpl != null) { _servantManager = adapterImpl.getServantManager(); } try { if(_endpoint.datagram()) { _acmTimeout = 0; } else { if(adapterImpl != null) { _acmTimeout = adapterImpl.getACM(); } else { _acmTimeout = _instance.clientACM(); } } if(adapterImpl != null) { _threadPool = adapterImpl.getThreadPool(); } else { _threadPool = instance.clientThreadPool(); } _threadPool.initialize(this); } catch(LocalException) { throw; } catch(System.Exception ex) { throw new SyscallException(ex); } }
public void download(string fullURL, string fileName, long offset, DownloadingCallback downloading, TimeoutCallback timeout, StartCallback start, FinishCallback finish) { mDownloadListLock.waitForUnlock(); DownloadInfo info = new DownloadInfo(); // 下载地址里需要将空格替换为%20 info.mURL = StringUtility.strReplaceAll(fullURL, " ", "%20"); info.mFileName = fileName; info.mDownloadingCallback = downloading; info.mStartCallback = start; info.mFinishCallback = finish; info.mTimeoutCallback = timeout; info.mDownloadOffset = offset; mDownloadList.Add(info); mDownloadListLock.unlock(); }
public bool RemoveTimeoutListener(TimeoutCallback callback) { return(this.RemoveTimeoutListener(callback, null)); }
public static Timeout AddTimeout(TimeSpan begin, TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { Timeout t = new Timeout(begin, timespan, repeat, data, callback); ITimerWatcher timer; timer = context.CreateTimerWatcher(begin, timespan, delegate { t.Run(app); if (!t.ShouldContinueToRepeat()) { t.Stop(); timer.Dispose(); } }); timer.Start(); return(t); }
public static void ConnectSSLAsync(string host, int port, Factory factory, object contextFactory, int timeout, ConnectedCallback callback, TimeoutCallback timeoutCallback, object state) { ConnectSSLAsync(host, port, factory, contextFactory, timeout, null, callback, timeoutCallback, state); }
public bool AddTimeoutListener(TimeoutCallback callback) { return(this.AddTimeoutListener(callback, null)); }
public static void AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { Timeout t = new Timeout (DateTime.UtcNow + timespan, timespan, repeat, data, callback); ioloop.AddTimeout (t); }
public static Timeout AddTimeout(TimeSpan timespan, object data, TimeoutCallback callback) { return(AddTimeout(timespan, RepeatBehavior.Single, data, callback)); }
public Timeout(TimeSpan span, IRepeatBehavior repeat, object data, TimeoutCallback callback) : this(TimeSpan.Zero, span, repeat,data, callback) { }
public static Timeout AddTimeout(TimeSpan begin, TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { Timeout t = new Timeout(begin, timespan, repeat, data, callback); ioloop.AddTimeout(t); return(t); }
public static void AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, TimeoutCallback callback) { AddTimeout (timespan, repeat, null, callback); }
public static Timeout AddTimeout(TimeSpan begin, TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { Timeout t = new Timeout (begin, timespan, repeat, data, callback); ITimerWatcher timer = null; timer = context.CreateTimerWatcher (begin, timespan, delegate { t.Run (app); if (!t.ShouldContinueToRepeat ()) { t.Stop (); timer.Dispose (); } }); timer.Start (); return t; }
public static void AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, TimeoutCallback callback) { AddTimeout(timespan, repeat, null, callback); }
// Utils IEnumerator SetTimeout(float time, TimeoutCallback Method) { yield return(new WaitForSecondsRealtime(time)); Method(); }
public static void AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { AppHost.AddTimeout(timespan, repeat, data, callback); }
public WuStateAsyncJobProxy(WuStateId id, string displayName, int timeoutSec, TimeoutCallback timeoutCallback, ProgressChangedCallback progressCallback) : base(id, displayName, timeoutSec, timeoutCallback, progressCallback) { }
public static Timeout AddTimeout(TimeSpan timespan, TimeoutCallback callback) { return AddTimeout (timespan, RepeatBehavior.Single, null, callback); }
public static Timeout AddTimeout(TimeSpan begin, TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { Timeout t = new Timeout (begin, timespan, repeat, data, callback); ioloop.AddTimeout (t); return t; }
public static Timeout AddTimeout(TimeSpan timespan, object data, TimeoutCallback callback) { return AddTimeout (timespan, RepeatBehavior.Single, data, callback); }
internal static extern void iAsyncWait(TimeoutCallback callback, Sirikata.Runtime.TimeClass t);
public Timeout(TimeSpan span, IRepeatBehavior repeat, object data, TimeoutCallback callback) : this(TimeSpan.Zero, span, repeat, data, callback) { }
public static bool AsyncWait(TimeoutCallback callback, Sirikata.Runtime.Time t) { if (callback==null) return false; iAsyncWait(callback,t.toClass()); return true; }
public static void SetupTickFunction(TimeoutCallback tc, Sirikata.Runtime.Time t) { long us=t.microseconds(); TimeoutCallback wrapped_tc=null; long estLocalTime=GetLocalTime().microseconds()+us*2; wrapped_tc=new TimeoutCallback(delegate(){ try { tc(); }finally { long delta=estLocalTime-GetLocalTime().microseconds(); estLocalTime+=us; if (delta>0) { iAsyncWait(wrapped_tc,new TimeClass((ulong)delta)); }else { iAsyncWait(wrapped_tc,new TimeClass()); } } }); iAsyncWait(wrapped_tc,t.toClass()); }
public static Timeout AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { return(AddTimeout(timespan, timespan, repeat, data, callback)); }
public static void AddTimeout(TimeSpan timespan, IRepeatBehavior repeat, object data, TimeoutCallback callback) { AddTimeout (timespan, timespan, repeat, data, callback); }