0

全て、

シリアル ポート データを読み取り、何らかのアクションを実行するプログラムがあります。

これを行う小さなコードを次に示します。

private void SerialDataReceivedEventHandler(object sender, SerialDataReceivedEventArgs e)
{
    try
    {


        SerialPort sp = (SerialPort)sender;
        Thread.Sleep(100);
        sCommdata = sp.ReadExisting();
        string[] splitter = new string[2];
        splitter = sCommdata.Split('\r');
        string switchMaker = splitter[0].Trim();
        switchMaker = switchMaker.Substring(0, 3);


        Dispatcher.Invoke(new UpdateKiosk(Reintialise), DispatcherPriority.Send, sCommdata);

    }
    catch (Exception ex)
    {
        //log data goes here
    }
}

会社のロゴをダブルクリックしてアプリケーションのパスワードを入力しない限り、アプリケーションは使用されるたびに自動的にリセットされます。正しいパスワードが入力されると、アプリケーションは完全に終了します。ここで、アプリケーション パスワードを WPF app.config に格納する次のコードを含めました。これが XML コードです。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
     <add key ="ApplicationPassword" value ="xxxxxxx"/> 
  </appSettings>
</Configuration>

上記のコードを追加すると、以下のコードが実行されますが、通知が必要なメソッド (再初期化) は通知を受け取りません。

  Dispatcher.Invoke (new UpdateKiosk(Reintialise),DispatcherPriority.Send, sCommdata);

再初期化メソッドは、Web サービス メソッドを呼び出して、アプリケーションのすべての初期設定を行います。

なにか提案を?

ありがとう

4

1 に答える 1

0

このコードと構成を使用することをお勧めします

<applicationSettings>
    <WpfApplication1.Properties.Settings>
        <setting name="ApplicationPassword" serializeAs="String">
            <value>xxxxxxx</value>
        </setting>
    </WpfApplication1.Properties.Settings>
</applicationSettings>

値を取得します

var result  = WpfApplication1.Properties.Settings.Default.ApplicationPassword.ToString()
于 2012-09-03T14:27:27.260 に答える