時には、一部のマシンで、まれにしかプログラムを使用していないクライアントが「パイプが閉じられています」例外が発生することがあります。これは、.WaitForConnection()にあるNamedPipeServerStreamで発生します。その後、アプリケーションは完全にクラッシュし、Windows例外を解放します。これは、NamedPipeClientStreamがスタンドアロンアプリケーションに情報を転送するときに発生します。パイプが閉じられている例外例外
主な機能: NamedPipeと一緒に通信するいくつかのツール(Officeツールバー、サービス、スタンドアロンの.netアプリケーション、およびlitleスターターexe)を書きました。 サービスは、常に開いている状態(.WaitForConnection();)のNamedPipeServerStreamを実行し、スタンドアロンアプリケーションもNamedPipeServerStreamを持ちます。 ツールバーとスターター.exeがサービスと通信します。スタンドアロンアプリケーションでのサービス
どのような種類の問題をパイプを解放できるかどうかは例外ですか? スタンドアロンアプリケーションに情報を送信するが、スタンドアロンアプリケーションが準備されていないため、ストリームを早期に閉じることは可能ですか?ここpipeserverのclientstream
using (NamedPipeClientStream pipeClient =
new NamedPipeClientStream(".", pipename, PipeDirection.Out))
{
// Wait for a client to connect
try
{
pipeClient.Connect(3000);
// send params to the form
using (StreamWriter sw = new StreamWriter(pipeClient))
{
sw.AutoFlush = true;
sw.WriteLine(sendtext);
}
}
// Catch the IOException that is raised if the pipe is
// broken or disconnected.
catch (Exception e)
{
if (sid != "")
{
connections.Remove(conName);
}
eventLog1.WriteEntry("SendText Fehler 1 " + e.Message);
}
finally
{
if (pipeClient.IsConnected)
{
pipeClient.WaitForPipeDrain();
}
pipeClient.Close();
pipeClient.Dispose();
}
例の例(その:各NamedPipeClientStreamに私は
編集私はpipeclientを閉じるbefor pipeClient.IsConnected場合waitforpipedrain ..助けを
感謝を行いますseperadスレッドで実行)
NamedPipeServerStream pipeServer;
PipeSecurity pipe_security = CreateSystemIoPipeSecurity();
do
string pipename = global::TOfficeCenter.Properties.Settings.Default.pipename;
string aText = "";
pipeServer = new NamedPipeServerStream(pipename, PipeDirection.In, ONE_INSTANCE, PipeTransmissionMode.Byte,
PipeOptions.None, IN_BUF_SIZE, OUT_BUF_SIZE, pipe_security);
try
{
// Verbindung zu TOfficeCenter.exe aufbauen
try
{
IsWaiting = true;
pipeServer.WaitForConnection();
IsWaiting = false;
using (StreamReader sr = new StreamReader(pipeServer))
{
string temp;
while ((temp = sr.ReadLine()) != null)
{
aText = aText + temp;
}
}
try
{
if (aText == "")
{
empfang(null);
}
else
{
if (aText != "KillPipe")
{ // XML empfangen
XmlDocumentTC xml = new XmlDocumentTC();
xml.LoadXml(aText);
empfang(xml);
}
}
}
catch (Exception)
{
empfang(null);
}
}
catch
{...........
}
}
catch (Exception e)
{...........
}
} while (running);
pipeServer.Close();
いずれかのアプリケーションでパイプが偶然閉じられていませんか? – svick
私は、クライアントデータがサーバ上で例外を起こしていると思います。これは未処理のため、サーバーがシャットダウンし、その例外がクライアントで生成されます。サーバーの例外ログを改善してこれを診断し、AppDomain.UnhandledExceptionイベントを実装します。 –
あなたの答えをありがとう。 – user1194383