本文整理汇总了C#中System.IO.Pipes.NamedPipeClientStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeClientStream.Close方法的具体用法?C# NamedPipeClientStream.Close怎么用?C# NamedPipeClientStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Pipes.NamedPipeClientStream
的用法示例。
在下文中一共展示了NamedPipeClientStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Close
public void Close()
{
Console.WriteLine(string.Format("closing pipe server {0}...", PipeName));
m_closing = true;
//emulate new client connected to resume listener thread
using (NamedPipeClientStream fakeClient = new NamedPipeClientStream(".", PipeName, PipeDirection.In))
{
try
{
fakeClient.Connect(100);
fakeClient.Close();
}
catch
{
//server was stopped already
}
}
if (m_listenerThread != null && m_listenerThread.IsAlive)
{
if (!m_listenerThread.Join(5000))
{
m_listenerThread.Abort();
}
}
m_listenerThread = null;
Console.WriteLine(string.Format("disconnecting clients from pipe {0}...", PipeName));
while (m_pipeStreams.Count > 0)
{
DisconnectClient(m_pipeStreams[0]);
}
Console.WriteLine(string.Format("Pipe server {0} stopped OK", PipeName));
}
示例2: ensureOnlyOne
private void ensureOnlyOne()
{
var pipeName = $"{this.GetType().FullName}.{winServiceInstaller.ServiceName}";
try
{
var serverStream = createNewNamedPipedServerStream(pipeName);
AsyncCallback ac = null;
ac = ar =>
{
showForm();
serverStream.Close();
serverStream = createNewNamedPipedServerStream(pipeName);
serverStream.BeginWaitForConnection(ac, null);
};
serverStream.BeginWaitForConnection(ac, null);
}
catch
{
try
{
var clientStream = new NamedPipeClientStream(pipeName);
clientStream.Connect();
clientStream.Close();
}
finally
{
this.DialogResult = DialogResult.Cancel;
this.Close();
Environment.Exit(0);
}
}
}
示例3: Main
public static void Main(string[] args)
{
if (args.Length > 0)
{
if (args[0] == "spawnclient")
{
var pipeClient = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut,
PipeOptions.None, TokenImpersonationLevel.Impersonation);
Console.WriteLine("Connecting to server...\n");
pipeClient.Connect();
StreamString ss = new StreamString(pipeClient);
if (ss.ReadString() == "I am the one true server!")
{
ss.WriteString(Environment.CurrentDirectory + "\\testdata.txt");
Console.Write(ss.ReadString());
}
else
{
Console.WriteLine("Server could not be verified.");
}
pipeClient.Close();
Thread.Sleep(4000); // Give the client process some time to display results before exiting.
}
}
else
{
Console.WriteLine("\n*** Named pipe client stream with impersonation example ***\n");
StartClients();
}
}
示例4: Connect
public void Connect(string pipeName, string serverName = ".", int timeout = 2000)
{
NamedPipeClientStream pipeStream = null;
try
{
pipeStream = new NamedPipeClientStream(serverName, pipeName, PipeDirection.InOut,
PipeOptions.Asynchronous, TokenImpersonationLevel.Impersonation);
pipeStream.Connect(timeout);
using (var stringStream = new StringStream(pipeStream))
{
if (OnConnected != null)
{
OnConnected(stringStream);
}
}
}
catch (Exception exception)
{
if (OnErrorOcurred != null)
{
OnErrorOcurred(exception);
}
}
finally
{
if (pipeStream != null && pipeStream.IsConnected)
{
pipeStream.Flush();
pipeStream.Close();
}
}
}
示例5: CheckUnenrolledHostShouldRemoved
public void CheckUnenrolledHostShouldRemoved()
{
CredentialReceiver.instance.Init();
ServerListHelper.instance.Init();
DatabaseManager.CreateNewConnection(dbName);
IXenConnection connection = DatabaseManager.ConnectionFor(dbName);
Session _session = DatabaseManager.ConnectionFor(dbName).Session;
DatabaseManager.ConnectionFor(dbName).LoadCache(_session);
Dictionary<string, string> config = cleanStack();
connection.LoadCache(_session);
int conSize = ServerListHelper.instance.GetServerList().Count;
NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", HealthCheckSettings.HEALTH_CHECK_PIPE, PipeDirection.Out);
pipeClient.Connect();
string credential = EncryptionUtils.ProtectForLocalMachine(String.Join(SEPARATOR.ToString(), new[] { connection.Hostname, connection.Username, connection.Password }));
pipeClient.Write(Encoding.UTF8.GetBytes(credential), 0, credential.Length);
pipeClient.Close();
System.Threading.Thread.Sleep(1000);
List<ServerInfo> con = ServerListHelper.instance.GetServerList();
Assert.IsTrue(con.Count == conSize + 1);
//1. If XenServer has not enroll, lock will not been set.
config = cleanStack();
config[HealthCheckSettings.STATUS] = "false";
Pool.set_health_check_config(_session, connection.Cache.Pools[0].opaque_ref, config);
Assert.IsFalse(RequestUploadTask.Request(connection, _session));
con = ServerListHelper.instance.GetServerList();
Assert.IsTrue(con.Count == conSize);
CredentialReceiver.instance.UnInit();
}
示例6: SendCommandToCore
public static bool SendCommandToCore(string machine, string command)
{
NamedPipeClientStream pipeClient =
new NamedPipeClientStream(machine, Kernel.MBCLIENT_MUTEX_ID,
PipeDirection.Out, PipeOptions.None);
StreamWriter sw = new StreamWriter(pipeClient);
try
{
pipeClient.Connect(2000);
}
catch (TimeoutException)
{
Logger.ReportWarning("Unable to send command to core (may not be running).");
return false;
}
try
{
sw.AutoFlush = true;
sw.WriteLine(command);
pipeClient.Flush();
pipeClient.Close();
}
catch (Exception e)
{
Logger.ReportException("Error sending commmand to core", e);
return false;
}
return true;
}
示例7: evaluate
public override void evaluate()
{
try
{
if ((bool)pinInfo["trigger"].value.data && lastInput != pinInfo["trigger"].value.data)
{
myPipe = new NamedPipeClientStream(".", "lavalamp winamp control", PipeDirection.InOut,
PipeOptions.None);
myPipe.Connect(500);
StreamWriter myWriter = new StreamWriter(myPipe);
myWriter.AutoFlush = true;
myWriter.Write(Cmd);
myPipe.Close();
}
lastInput = pinInfo["trigger"].value;
}
catch (ObjectDisposedException)
{
// todo - add option to ignore errors / errored state / etc
MessageBox.Show("Unable to contact winamp. Is it running? Is the plugin installed OK?");
}
catch (IOException)
{
// todo - add option to ignore errors / errored state / etc
MessageBox.Show("Unable to contact winamp. Is it running? Is the plugin installed OK?");
}
catch (System.TimeoutException)
{
MessageBox.Show("Unable to contact winamp. Is it running? Is the plugin installed OK?");
}
}
示例8: Main
static void Main(string[] args)
{
string[] simpleNames = { "Yukari", "Maki", "Zunko", "Akane", "Aoi", "Koh" };
string[] simpleNamesA = { "yukari", "maki", "zunko", "akane", "aoi", "koh" };
//引数のチェック
if (args.Length < 2) {
string mergeName = "";
for (int i = 0; i < simpleNames.Length; i++)
{
mergeName = mergeName + simpleNames[i];
//ワード間に", "をつける
if (i < simpleNames.Length - 1)
mergeName = mergeName + ", ";
}
Console.WriteLine("引数を指定してください: VoiceroidTClient"+ mergeName +" [会話内容];[音量0.0-2.0];[話速0.5-4.0];[高さ0.5-2.0];[抑揚0.0-2.0]");
return;
}
//引数に設定されたボイスロイドの名前をチェック
string selectedSimple = null;
for (int i = 0; i < simpleNames.Length; i++) {
if (args[0].CompareTo(simpleNames[i]) == 0 || args[0].CompareTo(simpleNamesA[i]) == 0) {
selectedSimple = simpleNames[i];
}
}
if (selectedSimple == null) {
string mergeName = "";
for (int i = 0; i < simpleNames.Length; i++)
{
mergeName = mergeName + simpleNames[i];
//ワード間に", "をつける
if (i < simpleNames.Length - 1)
mergeName = mergeName + ", ";
}
Console.WriteLine("第一引数に指定されたVOICEROIDの名前が正しくありません. 使用できる名前は次のとおりです: "+ mergeName);
return;
}
//サーバーとの通信処理を開始
string message = args[1];
try {
//サーバーのセッションを取得する
using (NamedPipeClientStream client = new NamedPipeClientStream("voiceroid_talker" + selectedSimple)) {
client.Connect(1000);
//サーバにーメッセージを送信する
byte[] buffer = UnicodeEncoding.Unicode.GetBytes(message);
client.Write(buffer, 0, buffer.Length);
byte[] response = new byte[4];
client.Read(response, 0, response.Length);
client.Close();
}
} catch (Exception e) {
//サーバーに接続できない時、通信エラーが発生した場合
Console.WriteLine("VoiceroidTServerによるサーバー, [voiceroid_talker" + selectedSimple + "]が見つかりません.");
}
}
示例9: CheckVaildPort
/// <summary>
/// Checks the valid port.
/// in future this could use lavalamp's methods to detect if a node is on a port
/// </summary>
/// <param name='sender'>
/// Sender.
/// </param>
/// <param name='e'>
/// E.
/// </param>
private void CheckVaildPort(object sender, EventArgs e)
{
try
{
bool success;
if (cboPort.Text.Contains("pipe"))
{
int pipeNameIndex = cboPort.Text.LastIndexOf(@"\");
using (NamedPipeClientStream pipe = new NamedPipeClientStream(cboPort.Text.Substring(pipeNameIndex, (cboPort.Text.Length - pipeNameIndex))))
{
pipe.Connect(50);
success = pipe.IsConnected;
pipe.Close();
}
}
else
{
using (SerialPort selectedPort = new SerialPort(cboPort.Text))
{
selectedPort.Open();
success = selectedPort.IsOpen;
selectedPort.Close();
}
}
if (success)
{
lblStatus.ForeColor = System.Drawing.Color.Green;
lblStatus.Text = "Free";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.DarkRed;
lblStatus.Text = "Cannot Open Port";
}
}
catch(Exception ex)
{
if (ex is AccessViolationException || ex is InvalidOperationException)
{
lblStatus.ForeColor = System.Drawing.Color.Orange;
lblStatus.Text = "Already Open";
}
else if (ex is ArgumentException)
{
lblStatus.ForeColor = System.Drawing.Color.Red;
lblStatus.Text = "Invaild Port";
}
else
{
lblStatus.ForeColor = System.Drawing.Color.DarkRed;
lblStatus.Text = "Cannot Open Port";
}
}
}
示例10: Start
// Use this for initialization
void Start()
{
System.IO.Pipes.NamedPipeClientStream clientStream = new System.IO.Pipes.NamedPipeClientStream ("mypipe");
clientStream.Connect (60);
byte[] buffer = ASCIIEncoding.ASCII.GetBytes ("Connected/n");
Debug.Log ("connected");
clientStream.Write (buffer, 0, buffer.Length);
clientStream.Flush ();
clientStream.Dispose ();
clientStream.Close ();
}
示例11: SendToPipe
void SendToPipe()
{
byte[] buffer = ASCIIEncoding.ASCII.GetBytes ("done");
System.IO.Pipes.NamedPipeClientStream clientStream = new System.IO.Pipes.NamedPipeClientStream ("mypipe");
clientStream.Connect (System.TimeSpan.MaxValue.Seconds);
clientStream.WaitForPipeDrain();
clientStream.Write (buffer, 0, buffer.Length);
clientStream.Flush ();
clientStream.Dispose();
clientStream.Close();
}
示例12: Main
static void Main(string[] args)
{
string pipeString = "Hello hello hello!";
byte[] pipeBuffer = new byte[pipeString.Length * sizeof(char)];
System.Buffer.BlockCopy(pipeString.ToCharArray(), 0, pipeBuffer, 0, pipeString.Length);
NamedPipeClientStream pipe = new NamedPipeClientStream(".", "MyServicePipe", PipeDirection.Out, PipeOptions.WriteThrough, System.Security.Principal.TokenImpersonationLevel.Impersonation);
pipe.Connect();
pipe.Write(pipeBuffer, 0, pipeBuffer.Length);
Thread.Sleep(10000);
pipe.Close();
}
示例13: ConnectAsync
// Asynchronously create a new connection
public async Task<Tuple<Int32, string>> ConnectAsync(string endpoint)
{
// Parse the endpoint. It should be formatted as
// "\\server\pipe\name".
string [] components = endpoint.Split(new char[] { '\\' });
if (components.Length != 5)
{
return Tuple.Create(-1, "invalid endpoint format");
}
// Create the connection
// NOTE: It is essential that the PipeOptions.Asynchronous option be
// specified, or the ReadAsync and WriteAsync methods will block
// (and I don't mean they'll call await and halt - I mean they'll
// never return a Task object)
var connection = new NamedPipeClientStream(
components[2],
components[4],
PipeDirection.InOut,
PipeOptions.Asynchronous
);
// Try to connect asynchronously
try
{
await connection.ConnectAsync();
}
catch (Exception e)
{
return Tuple.Create(-1, e.Message);
}
// Store the connection
Int32 connectionId = -1;
lock (this)
{
// Compute the next connection id. Watch for overflow, because
// we use -1 as the invalid identifier.
if (_nextConnectionId < 0)
{
connection.Close();
return Tuple.Create(-1, "connection ids exhausted");
}
connectionId = _nextConnectionId++;
// Do the storage
_connections[connectionId] = connection;
}
// All done
return Tuple.Create(connectionId, "");
}
示例14: Main
private static void Main(string[] args)
{
try
{
if (args.Length > 1)
{
var pipeGuid = args[0];
NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", pipeGuid, PipeDirection.InOut);
pipeClient.Connect();
var dlls = args.Skip(2).ToArray();
var nunit3ConsoleExePath = Encoding.UTF8.GetString(Convert.FromBase64String(args[1]));
Write(pipeClient, Discover(dlls, pipeClient, nunit3ConsoleExePath));
pipeClient.WaitForPipeDrain();
pipeClient.Close();
}
}
catch (Exception ex)
{
var sb = new StringBuilder();
sb.AppendLine(ex.Message);
sb.AppendLine(ex.StackTrace);
foreach (var arg in args)
sb.AppendLine(arg);
string fileName = DateTime.Now.ToString("YYYY-MM-DD hh:mm:ss");
Guid parsedGuid;
if (args.Length > 0 && Guid.TryParse(args[0], out parsedGuid))
fileName = parsedGuid.ToString();
try
{
File.WriteAllText(fileName, sb.ToString());
}
catch (Exception) { }
Console.WriteLine(sb.ToString());
}
}
示例15: pipeWorker
private void pipeWorker (object args)
{
try
{
string value = args.ToString();
_pipeStream = new NamedPipeClientStream( ".", _pipeName, PipeDirection.Out );
_pipeStream.Connect();
byte[] messageBytes = Encoding.UTF8.GetBytes( value );
_pipeStream.Write( messageBytes, 0, messageBytes.Length );
_pipeStream.WaitForPipeDrain();
_pipeStream.Close();
Thread.Sleep( 5000 );
_sendingFinished.Set();
}
catch
{
}
}