private void startSendPipe(object o, DoWorkEventArgs ea) {
NamedPipeServerStream sendPipe = new NamedPipeServerStream("ShutdownPipeGet", PipeDirection.Out,
1,
PipeTransmissionMode.Byte,
PipeOptions.Asynchronous); //IPC server sender
StreamWriter sw;
IAsyncResult aResult = sendPipe.BeginWaitForConnection(
delegate(IAsyncResult iar) {
try {
sw = new StreamWriter(sendPipe);
sw.WriteLine(waitTime.ToString()); //send integer converted to string across
sendPipe.WaitForPipeDrain(); //wait for client to finish download
sw.Close(); //Close streams when done
} catch (IOException ioerr) {
Console.WriteLine("Send connection was unexpectedly broken to ShutdownAppGUI.");
} catch (Exception err) {
Console.WriteLine("Unexpected error on send connection: " + err.Message);
}
},
null
);
//keep worker going until either the info has been sent or background worker cancel is requested.
while (!ea.Cancel && !aResult.IsCompleted) {
Thread.Sleep(1000);
}
if (!aResult.IsCompleted) { sendPipe.EndWaitForConnection(aResult); }
}
NamedPipeClientStream npc = new NamedPipeClientStream(".", "ShutdownPipeGet", PipeDirection.In); //connect to ShutdownAppCLI(server) to get waitime
StreamReader sr;
try {
npc.Connect();
sr = new StreamReader(npc);
String theTime = sr.ReadToEnd();
sr.Close();
waitTime = Int32.Parse(theTime); //converting string to integer
TimeLabel.Text = waitTime.ToString();
} catch (Exception err) {
MessageBox.Show("ShutdownAppGUI Error: " + err.Message);
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE