0

我正在尝试通过我的代码连接到打印机,然后在打印机上应用安全设置。在应用安全功能之前,它会在以下代码模块中检查密码。代码在行后挂起

流.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 回答