0

コードを使用してプリンターに接続し、プリンターにセキュリティ設定を適用しようとしています。セキュリティ機能を適用する前に、次のコードモジュールでパスワードをチェックします。行の後にコードがハングする

stream.Flush()

if (responseStr.IndexOf(PrinterSecurityConstants.NewPrinterPass) > 0)
{
    LogUtility.Info(PrinterSecurityConstants.ValidateUserNamePassword);

    data = System.Text.Encoding.ASCII.GetBytes(
        ConfigurationManager.AppSettings[PrinterSecurityConstants.CurrentPass]
        .ToLower() + CommonConstant.Carriagereturn);
    stream.Write(data, 0, data.Length);
    stream.Flush();
    bytes = stream.Read(dataResponse, 0, dataResponse.Length);
    responseStr = System.Text.Encoding.ASCII.GetString(dataResponse, 0, bytes);
}

このコードが機能するために私がする必要があること。

4

1 に答える 1

0

Stream.Read() は、読み取り可能なバイトができるまでブロックします。これを行いたくない場合は、読み取りモードを変更する必要があります。

于 2012-10-09T20:58:57.343 に答える