/// <summary> /// 他プロセスへメッセージを送信 /// </summary> /// <param name="items"></param> public static void Send(string[] items) { PipeMessage message = new PipeMessage() { Items = items, }; using (var sw = new StreamWriter(pipemessage_FileName, false, Encoding.UTF8)) { sw.Write(Newtonsoft.Json.JsonConvert.SerializeObject(message)); } using (NamedPipeClientStream ps = new NamedPipeClientStream(".", PIPE_NAME, PipeDirection.Out)) { try { ps.Connect(PIPE_CONNECT_TIMEOUT); using (StreamWriter sw = new StreamWriter(ps)) { sw.Write(SEND_MESSAGE); } } catch { } } }
/// <summary> /// パイプ受け取り後の処理 /// </summary> /// <param name="mainWindow"></param> private static void UpdateImageForMainWindow(MainWindow mainWindow) { try { using (var sr = new StreamReader(pipemessage_FileName, Encoding.UTF8)) { PipeMessage message = Newtonsoft.Json.JsonConvert.DeserializeObject <PipeMessage>(sr.ReadToEnd()); if (message.Items == null || message.Items.Length == 0) { mainWindow.Activate(); mainWindow.Focus(); } else { // 何も選択せずにGazoView.exeを実行した場合は、すでに起動しているウィンドウを最前面に。 Item.ImageStore.SetItems(message.Items); mainWindow.UpdateImage(0); } } File.Delete(pipemessage_FileName); } catch { } }