代码在 Network Stream.Read 之后挂起



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

流。同花顺()

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);
}

我需要做什么才能使此代码正常工作。

Stream.Read() 块,直到有字节可供读取。如果您不想这样做,则需要更改阅读模式。

最新更新