应用 工业PC W7旗下64位
问题: 我们经常在断电(切断)时出现问题,看起来像我们使用的中断损坏文件设置如下: 的 Properties.Settings.Default。
当应用程序再次启动时,显示以下消息:
**************异常文本**************
System.Configuration.ConfigurationErrorsException:配置系统初始化失败 -
在应用程序grapich中使用设置文件重新加载旧值(Windows图表框架3.5) 任何想法帮助?如何保护系统文件中的写入/读取过程 是否有任何“FileClose”以保护突然断电。
文件设置相同:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="WindowsFormsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<appSettings>
<add key="Ip_Box" value="192.168.214.241"/>
<add key="Report_Box" value="Report"/>
<add key="MaxValSp_Box" value="1000"/>
<add key="NumSp_Box" value="10"/> <!--Numero asse mand 1 es:10 x RPM -->
<add key="NumDriveSp_Box" value="7"/> <!--Indice n. Drive Sp1:CU[0],NX[1],NX[2],NX[3],CU_L1[4],..SP[7]-->
<add key="NumSp2_Box" value="11"/> <!--Numero asse mand 2 es:10 x RPM -->
<add key="NumDriveSp2_Box" value="8"/> <!--Indice n. Drive Sp2-->
<add key="MaxValSp2_Box" value="10000"/>
<add key="NumParRead_Box" value="33"/> <!--R33 coppia attuale-->
<add key="Language" value="ita"/> <!--Language (ita-eng-deu ecc...)-->
<!-- HOME PAGE ****************************************************** -->
<add key="Table1" value="1"/> <!--1=On, 0=Off -->
<add key="Table2" value="1"/> <!--1=On, 0=Off -->
<add key="Table3" value="0"/> <!--1=On, 0=Off -->
<add key="ActivateRef." value="1"/> <!--1=On, 0=Off -->
<!-- H.S.KEY ******************************************************* -->
<add key="Hsk3" value="1"/> <!--1=On, 0=Off -->
<add key="Hsk4" value="1"/> <!--1=On, 0=Off -->
<add key="Hsk5" value="1"/> <!--1=On, 0=Off -->
<add key="Hsk6" value="1"/> <!--1=On, 0=Off -->
<add key="Hsk7" value="1"/> <!--1=On, 0=Off -->
<add key="Hsk8" value="1"/> <!--1=On, 0=Off -->
<!-- TIRANTI ******************************************************* -->
<add key="adrDB" value="601"/> <!-- DB tabella pressioni -->
<add key="adrDBW" value="80"/> <!-- DBW iniziale tabella pressioni -->
<add key="adrDBWCnt" value="22960"/> <!-- Num tot word db601 FCT DATI -->
<!-- HT8 ******************************************************* -->
<add key="Ax1" value="X"/>
<add key="Ax2" value="Y"/>
<add key="Ax3" value="Z"/>
<add key="Ax4" value="A"/>
<add key="Ax5" value="W"/>
<add key="Ax6" value="C"/>
<add key="Ax7" value="W1"/>
<add key="Ax8" value="W2"/>
<add key="Ax9" value="W3"/>
<add key="Ax10" value="B1"/>
<add key="Ax11" value="B2"/>
<add key="Ax12" value="B3"/>
<add key="Ax13" value="SP"/>
<add key="Ax14" value="A2"/> <!-- DBX126.4=1 Ax4 Visual Ax14 -->
<add key="Ax15" value="B2"/> <!-- DBX126.4=1 Ax5 Visual Ax15 -->
<add key="Ax16" value="C2"/> <!-- DBX126.4=1 Ax6 Visual Ax16 -->
<add key="Ax1Num" value="1"/> <!-- 0=Off, 1,2..ordine Visualizz -->
<add key="Ax2Num" value="2"/>
<add key="Ax3Num" value="3"/>
<add key="Ax4Num" value="4"/>
<add key="Ax5Num" value="5"/>
<add key="Ax6Num" value="6"/>
<add key="Ax7Num" value="7"/>
<add key="Ax8Num" value="8"/>
<add key="Ax9Num" value="9"/>
<add key="Ax10Num" value="10"/>
<add key="Ax11Num" value="11"/>
<add key="Ax12Num" value="12"/>
<add key="Ax13Num" value="13"/>
<add key="Ax14Num" value="14"/>
<add key="Ax15Num" value="15"/>
<add key="Ax16Num" value="16"/>
<add key="RefreshAxisTime" value="800"/> <!-- Tempo refresh quote assi -->
<add key="RefreshAxisPriority" value="2"/> <!-- 0=Low - 1=Standard - 2=hight -->
<!-- Tempo refresh quote assi -->
<!-- Tab Pressioni ***************************************************** -->
<add key="Cmp1" value="Prs I° Tirante Montante AP16 "/>
<add key="Cmp2" value="Prs II° Tirante Montante AP17 "/>
<add key="Cmp3" value="Prs III° Tirante Montante AP18 "/>
<add key="Cmp4" value="Prs Controtiro In calcolata "/>
<add key="Cmp5" value="Prs Controtiro Auto calcolata "/>
<add key="Cmp6" value="Prs Controtiro totale calcolata"/>
<add key="Cmp7" value="Prs Tir Slitta Interno AP19 "/>
<add key="Cmp8" value="Prs Tir Slitta Est. Slitta AP9 "/>
<add key="Cmp9" value="Prs feedback Proporz.CT "/>
<add key="Cmp10" value="Prs feedback Proporz.TI "/>
<add key="Cmp11" value="Prs Pattino 25 IN73 Verticale "/>
<add key="Cmp12" value="Prs Pattino 26 IN74 Verticale "/>
<add key="Cmp13" value="Prs Pattino 54 IN75 Vertical "/>
<add key="Cmp14" value="Prs Pattino_55 IN76 Verticale "/>
<add key="Cmp15" value="Prs blc leggero TRT1 "/>
<add key="Cmp16" value="Prs blc forte TRT1 "/>
<add key="Cmp17" value="Prs Meato 25 IN73 Vert.(calc. "/>
<add key="Cmp18" value="Prs Meato 26 IN74 Vert (calc) "/>
<add key="Cmp19" value="Prs Meato_54_IN75 Vert (calc) "/>
<add key="Cmp20" value="Prs Meato_55_IN76 Vert (calc) "/>
<add key="Cmp21" value="Prs blc leggero TRT2 "/>
<add key="Cmp22" value="Prs blc forte TRT2 "/>
<add key="Cmp1Num" value="1"/> <!-- 0=Off, 1,2..ordine Visualizz -->
<add key="Cmp2Num" value="2"/>
<add key="Cmp3Num" value="3"/>
<add key="Cmp4Num" value="4"/>
<add key="Cmp5Num" value="5"/>
<add key="Cmp6Num" value="6"/>
<add key="Cmp7Num" value="7"/>
<add key="Cmp8Num" value="8"/>
<add key="Cmp9Num" value="9"/>
<add key="Cmp10Num" value="10"/>
<add key="Cmp11Num" value="11"/>
<add key="Cmp12Num" value="12"/>
<add key="Cmp13Num" value="13"/>
<add key="Cmp14Num" value="14"/>
<add key="Cmp15Num" value="15"/>
<add key="Cmp16Num" value="16"/>
<add key="Cmp17Num" value="17"/>
<add key="Cmp18Num" value="18"/>
<add key="Cmp19Num" value="19"/>
<add key="Cmp20Num" value="20"/>
<add key="Cmp21Num" value="21"/>
<add key="Cmp22Num" value="22"/>
<!-- Tab Temp ***************************************************** -->
<add key="Tmp1" value="IN06 T.Ambiente "/>
<add key="Tmp2" value="IN18 T.Mand Idrostatica "/>
<add key="Tmp3" value="IN71 T.Mand Olio Cinematismi "/>
<add key="Tmp4" value="IN72 T.Mand Frigo Cinematismi "/>
<add key="Tmp5" value="IN70 T.Scarico Bussola di Raff "/>
<add key="Tmp6" value="IN21 T.I°Coppia Cuscinetti Ant "/>
<add key="Tmp7" value="IN15 T.II°Coppia Cuscinetti Ant"/>
<add key="Tmp8" value="IN22 T.Copp.Cuscinetti Centrali"/>
<add key="Tmp9" value="IN11 T.Olio Raff. Bareno "/>
<add key="Tmp10" value="IN08 T.Testa(TUP*)/II°CorpoTTWM"/>
<add key="Tmp11" value="IN69 T.Fl. Raffr. Motore MMand "/>
<add key="Tmp12" value="IN68 T.Piastra Interfaccia Tes "/>
<add key="Tmp13" value="IN99 T.Olio Mand.Idrost. Bareno"/>
<add key="Tmp14" value="IN90 T.Cusc Ant.Irrigidit Baren"/>
<add key="Tmp15" value="IN53 T.Int I° Corpo Testa/TTWM "/>
<add key="Tmp16" value="IN18 Mandata Idrostatica TRT1 "/>
<add key="Tmp17" value="IN18 Mandata Idrostatica TRT2 "/>
<add key="Tmp1Num" value="1"/> <!-- 0=Off, 1,2..ordine Visualizz -->
<add key="Tmp2Num" value="2"/>
<add key="Tmp3Num" value="3"/>
<add key="Tmp4Num" value="4"/>
<add key="Tmp5Num" value="5"/>
<add key="Tmp6Num" value="6"/>
<add key="Tmp7Num" value="7"/>
<add key="Tmp8Num" value="8"/>
<add key="Tmp9Num" value="9"/>
<add key="Tmp10Num" value="10"/>
<add key="Tmp11Num" value="11"/>
<add key="Tmp12Num" value="12"/>
<add key="Tmp13Num" value="13"/>
<add key="Tmp14Num" value="14"/>
<add key="Tmp15Num" value="15"/>
<add key="Tmp16Num" value="16"/>
<add key="Tmp17Num" value="17"/>
<!-- Grafico Temp ************************************************* -->
<add key="NumSonde" value="17"/> <!-- Num sonde Visualizzabili -->
<add key="NomiSonde" value="IN06;IN77;IN71;IN72;IN70;IN21;IN15;IN22;IN11;IN08;IN69;IN68;IN99;IN90;IN53;IN18;IN19"/>
<add key="SogliaMinX" value="0"/> <!-- Origine Base tempi -->
<add key="SogliaMaxX" value="600"/> <!-- MAX Base tempi -->
<add key="IntervalloX" value="60"/> <!-- Step Base tempi -->
<add key="SogliaMinY" value="20"/>
<add key="SogliaMaxY" value="60"/>
<add key="IntervalloY" value="2"/>
<!--
********************************************************************************
Parametri inizializzazione Mag.Ute (LibNodave)
********************************************************************************
-->
<add key="Ip" value="192.168.214.1"/> <!--Indirizzo IP CN -->
<add key="RefreshTime" value="1000"/> <!--Tempo di Clock (refresh) -->
<add key="TimeoutConnection" value="30000"/> <!--Tempo di riconnesione -->
<add key="textNumPocket" value="100"/> <!--Numero posti magazzino -->
<!--
********************************************************************************
-->
<!--
********************************************************************************
Pulsanti opzione Mag.Ute
********************************************************************************
-->
<add key="BalluffActive" value="0"/> <!--0=Off - 1=On [Pulsante Balluff] -->
<!--
********************************************************************************
-->
</appSettings>
<userSettings>
<WindowsFormsApplication1.Properties.Settings>
<setting name="MachineTimeWorkTot" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="MachineTimeManualTot" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="MachineTimeStopTot" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="MachineTimeWorkDay" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="MachineTimeManualDay" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="MachineTimeStopDay" serializeAs="String">
<value>00:00:00</value>
</setting>
<setting name="NumDay" serializeAs="String">
<value />
</setting>
<setting name="ck1Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck2Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck3Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck4Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck5Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck6Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck7Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck8Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck9Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck10Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck11Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ck12Green" serializeAs="String">
<value>False</value>
</setting>
<setting name="ckMoGreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="ckTuGreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="ckWeGreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="ckThGreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="ckFrGreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="ckSaGreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="ckSuGreen" serializeAs="String">
<value>False</value>
</setting>
<setting name="tbWeektimeGreen" serializeAs="String">
<value>00:00</value>
</setting>
<setting name="T1Green" serializeAs="String">
<value>0</value>
</setting>
<setting name="T2Green" serializeAs="String">
<value>0</value>
</setting>
<setting name="T3Green" serializeAs="String">
<value>0</value>
</setting>
<setting name="T4Green" serializeAs="String">
<value>0</value>
</setting>
<setting name="T5Green" serializeAs="String">
<value>0</value>
</setting>
<setting name="T6Green" serializeAs="String">
<value>0</value>
</setting>
<setting name="T7Green" serializeAs="String">
<value>0</value>
</setting>
<setting name="T8Green" serializeAs="String">
<value>0</value>
</setting>
</WindowsFormsApplication1.Properties.Settings>
</userSettings>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
我将配置文件保存在计时器中。 我使用此代码进行保存:(示例: Properties.Settings.Default.MachineTimeWorkTot = timeMachineWork.ActualVal; Properties.Settings.Default.Save())
非常感谢
答案 0 :(得分:0)
通常ApplicationSettingsBase
不处理电源故障情况。
我的第一个也是最重要的建议是使用 UPS 来处理这种情况。服用避孕药并接受无论你做什么,你都没有100%可靠的软件解决方案(充其量问题可能缓解,并且通过精心设计的软件实施和/或避免腐败有文件系统支持。)
现在我假设你出去买了一台UPS,你想让你的软件更可靠。你需要做的就是:
现在,如果您继续使用ApplicationSettingsBase
,那么您可以在这里停下来。你可能想要处理ConfigurationLoading
事件,但它只是 hacky 并且我不想提出它。或者,您可以使用自定义ConfigurationSection
并尝试以更可靠的方式保存数据:
1)将您的设置保存到新文件Your App.exe.config.new
。
2)将现有设置的副本复制到Your App.exe.config.bak
。
3)将Your App.exe.config
替换为Your App.exe.config.new
。
4)可选择删除.bak
和.new
个文件(除非你想保留它们进行恢复......不知何故)。
请注意,第2点,第3点和部分4由System.IO.File.Replace()
函数处理。不要试图重新实施它,除非你确保使其正确并增加一些价值。
所有这些都说......你在配置文件中保存了应用程序状态。在我看来,它不是正确的用法。它们不是为此目的而设计的。您可以考虑为您的州使用更好,更可靠的存储:本地数据库怎么样?它带有内置的可靠I / O(比我们可能期望的那样手动。甚至没有提到其他优点(查询值的可能性,在进程之间内在共享,可选择记录,易于更新/部署/合并等等......)
答案 1 :(得分:0)
**WORKAROUND WITH EXTERNAL SIGNAL**
早上好......目前我们通过解决方法解决了这个问题:
通过PLC位捕获UPS信号(使用电池)并与PC共享此信息;
将UPS信息放入计时器中,如果为真则停止计时器并使 Application.Exit();
在Form_Closed()事件中移动设置备份,为
我试图抓住计算机关机事件,但这很复杂。 这个解决方案功能强大,但更好的解决方案是使用pc shutdown事件而不是UPS bit。
全部谢谢