public static void SomeMethod() { Threading.Thread t = new Threading.Thread(() => { try { while (true) { dynamic server = new NamedPipeServerStream("Closer", PipeDirection.InOut, -1); server.WaitForConnection(); if (!server.IsConnected) { return; } dynamic reader = new IO.StreamReader(server); dynamic casetxt = reader.ReadToEnd(); server.Close(); RootForm.Invoke(() => { if (casetxt == "End") { System.Environment.Exit(0); } }); } } catch (Exception ex) { // try/catch required in all child threads as error silently ends app. // log it... } }); t.IsBackground = true; t.Name = "EnderListener"; t.Start(); }
/// <summary> /// Get the string of the specified Resource in the assembly /// </summary> /// <param name="assembly"></param> /// <param name="name"></param> /// <param name="encoding"></param> /// <returns></returns> static public string GetManifestResourceString(this Assembly assembly, Encoding encoding, params string[] name) { IO.Stream stream = assembly.GetManifestResourceStream(name); if (stream != null) { using (IO.StreamReader reader = new IO.StreamReader(stream, encoding, true, 2048)) return(reader.ReadToEnd()); } return(null); }
public static Newtonsoft.Json.Linq.JObject Parse(this HttpContext context) { if (context == null) { throw new ArgumentNullException("context"); } HttpRequest req = context.Request; if (req.ContentType == "application/x-www-form-urlencoded") { Newtonsoft.Json.Linq.JObject data = new Newtonsoft.Json.Linq.JObject(); for (int i = 0; i < req.Form.Count; i++) { data[req.Form.Keys[i]] = req.Form[i]; } return(data); } else if (String.Compare("POST", req.HttpMethod, true) == 0) { IO.StreamReader reader = new IO.StreamReader(req.InputStream); try { try { string data = reader.ReadToEnd(); if (!string.IsNullOrWhiteSpace(data)) { return(Newtonsoft.Json.Linq.JObject.Parse(data)); } return(new Newtonsoft.Json.Linq.JObject()); } catch { return(null); } } finally { reader.Dispose(); } } else { return(new Newtonsoft.Json.Linq.JObject()); } }