public void SaveSettings() { new XDocument( new XElement(Tag_Root, new XElement(Tag_NamedPipeAddress, NamedPipeAddress), new XElement(Tag_AutoConnect, AutoConnect.ToString()), new XElement(Tag_TimePaddingForLoop, TimePaddingForLoop.ToString()), new XElement(Tag_LoopSelection, LoopSelection.ToString()), new XElement(Tag_LoopNumber, LoopNumber.ToString()), new XElement(Tag_PlayMode, PlayMode.ToString()), new XElement(Tag_Volume, new XElement(Tag_VolumeValue, VolumeValue.ToString()), new XElement(Tag_VolumeMute, VolumeMute.ToString())), new XElement(Tag_Documents, DocumentByDocumentGuid.Select(x => new XElement(Tag_Document, new XAttribute(Att_Document_Id, x.Key), new XElement(Tag_Document_Name, x.Value.Name), new XElement(Tag_Media, x.Value.Media)))), new XElement(Tag_MinimalSeverityToShowInLog, MinimalSeverityToShowInLog.ToString()), new XElement(Tag_Window, new XElement(Tag_Top, WindowTop.ToString()), new XElement(Tag_Left, WindowLeft.ToString()), new XElement(Tag_Width, WindowWidth.ToString()), new XElement(Tag_Height, WindowHeight.ToString()), new XElement(Tag_Maximized, WindowMaximized.ToString()), new XElement(Tag_AlwaysOnTop, AlwaysOnTop.ToString())), new XElement(Tag_VlcLibPath, VlcLibPath), new XElement(Tag_DoNotAskAgain, FontMissingWindowDoNotAskAgain.ToString())) ).Save(SettingsPath); }
private void CheckFSPTimeout() { //每一次Send之后,都会检测一下。 if (m_CheckFSPTimeoutSeq == 0) { m_CheckFSPTimeoutSeq = m_FSPCodec.CurrentSEQ; if (m_CheckFSPTimeoutSeq == m_FSPCodec.ConfirmSEQ) { m_CheckFSPTimeoutSeq = 0; } else { //启动超时跟踪 m_CheckFSPTimeoutStartTicks = DateTime.Now.Ticks; m_CheckFSPTimeoutLastTicks = m_CheckFSPTimeoutStartTicks; } } else { //如果上面检测到有可能超时,则99MS后再检测一下 if (LoopNumber.loop_ushort_more_than(m_FSPCodec.ConfirmSEQ + 1, m_CheckFSPTimeoutSeq)) { //说明需要Check的SEQ已经被确认了 m_CheckFSPTimeoutSeq = 0; m_CheckFSPTimeoutStartTicks = 0; m_CheckFSPTimeoutReconnTicks = 0; m_WaitForSendAuth = false; if (m_IsFSPTimeout) { m_IsFSPTimeout = false; Debuger.LogWarning(LOG_TAG, "CheckFSPTimeout() Timeout end!"); //超时结束 if (m_FSPTimeoutHandler != null) { m_FSPTimeoutHandler(this, -1); } } } else { //那么Check的SEQ还没有被确认,确实超时了至少99MS //这个时候有可能是网络繁忙,并没有物理断线,所以有1秒的缓冲 long nowticks = DateTime.Now.Ticks; //每0.5秒检测一次是否真正超时 long passticks = nowticks - m_CheckFSPTimeoutLastTicks; if (passticks >= FSP_TIMEOUT_CHECK_TICKS)// { m_CheckFSPTimeoutLastTicks = nowticks; ///追加一个授权验证... m_WaitForSendAuth = true; //每2秒触发一次超时逻辑 passticks = nowticks - m_CheckFSPTimeoutStartTicks; int timeout_ms = (int)(passticks / 10000);//超时时长 if (passticks >= FSP_TIMEOUT_TICKS) { //触发[第]1次超时 if (!m_IsFSPTimeout) { m_IsFSPTimeout = true; Debuger.LogWarning(LOG_TAG, "CheckFSPTimeout() Timeout begin! CurrentSEQ = {0}, ConfirmSEQ = {1}", m_FSPCodec.CurrentSEQ, m_FSPCodec.ConfirmSEQ); timeout_ms = 0; m_CheckFSPTimeoutStartTicks = nowticks; m_CheckFSPTimeoutReconnTicks = nowticks; ///追加一个授权验证... m_WaitForSendAuth = true; } else { Debuger.LogWarning(LOG_TAG, "CheckFSPTimeout() Timeout happen: {0}ms, CurrentSEQ = {1}, ConfirmSEQ = {2}", timeout_ms, m_FSPCodec.CurrentSEQ, m_FSPCodec.ConfirmSEQ); } //触发超时逻辑 if (m_FSPTimeoutHandler != null) { //如果timeout_ms为0,则表示是触发第1次超时。如果非0,则表示已持续进入超时多少MS了 m_FSPTimeoutHandler(this, timeout_ms); } } //触发超时了 if (m_IsFSPTimeout) { //但不是第1次超时 if (nowticks - m_CheckFSPTimeoutReconnTicks >= FSP_TIMEOUT_TICKS) { m_CheckFSPTimeoutReconnTicks = nowticks; m_WaitForReconnect = true; Debuger.LogWarning(LOG_TAG, "CheckFSPTimeout() Timeout, try reconnect, CurrentSEQ = {1}, ConfirmSEQ = {2}", timeout_ms, m_FSPCodec.CurrentSEQ, m_FSPCodec.ConfirmSEQ); } } } } } }