private static void SetFailureTimer(TheTimedRequest <T> tReq, int pTimeOut) { Timer tTimer = null; if (pTimeOut > 0) { tTimer = new Timer(sinkRequestFailed, tReq, TheBaseAssets.MyServiceHostInfo.TO.StoreRequestTimeout * 1000, Timeout.Infinite); } tReq.MyTimer = tTimer; }
private static void sinkRequestFailed(object state) { TheDiagnostics.SetThreadName("TimedRequestFailed", true); TheTimedRequest <T> req = state as TheTimedRequest <T>; if (state != null) { TheTimedRequest <T> tReq = req; lock (MyStoreRequestsLock) { if (MyStoreRequests.ContainsKey(tReq.MagicID.ToString())) { TheBaseAssets.MySYSLOG.WriteToLog(472, TSM.L(eDEBUG_LEVELS.OFF) ? null : new TSM("TheTimedCallbacks", "Timed-Request Timed Out", eMsgLevel.l2_Warning)); MyStoreRequests.RemoveNoCare(tReq.MagicID.ToString()); tReq.MyRequest("Timed-Request Timed Out", (T)tReq.Cookie); } } } }
/// <summary> /// Adds a new callback to the waiting list /// </summary> /// <param name="pCallBack">The callback to be called</param> /// <param name="pTimeOut">A timeout after which the callback will be called if it has not fired before.</param> /// <param name="pCookie">A cookie that will be fired with the callback to be sent back to the caller</param> /// <returns></returns> public static string AddTimedRequest(Action <string, T> pCallBack, int pTimeOut, object pCookie) { TheTimedRequest <T> tReq = new TheTimedRequest <T> { MyRequest = pCallBack, MagicID = Guid.NewGuid(), Cookie = pCookie }; string Magix = tReq.MagicID.ToString(); SetFailureTimer(tReq, pTimeOut); lock (MyStoreRequestsLock) { if (MyStoreRequests.ContainsKey(tReq.MagicID.ToString())) { MyStoreRequests[tReq.MagicID.ToString()] = tReq; } else { MyStoreRequests.TryAdd(tReq.MagicID.ToString(), tReq); } } return(Magix); }