/// <summary> /// Allows cancelling of a previously requested variable, if it is no-longer needed /// </summary> /// <param name="request">SimVar Request to cancel</param> public static bool CancelRequest(SimConnectVariable request) { WriteLog("Start CancelRequest(SimConnectVariable)"); var result = false; if (simConnect != null && IsConnected && Requests.Any(x => x.Value.Name == request.Name && x.Value.Unit == request.Unit)) { lock (Requests) { try { var submittedRequest = Requests.First(x => x.Value.Name == request.Name && x.Value.Unit == request.Unit); var requestId = submittedRequest.Key; if (requestId > -1) { //simConnect.ClearDataDefinition((SIMVARDEFINITION)requestId); simConnect.ClearClientDataDefinition((SIMVARDEFINITION)requestId); Requests.Remove(requestId); RemoveTimer(requestId); result = true; } } catch (Exception ex) { WriteLog(string.Format("Cancellation Error: {0}", ex.Message), EventLogEntryType.Error); } } } WriteLog("End CancelRequest(SimConnectVariable)"); return(result); }