Esempio n. 1
0
        private static void PipeConnectionCallBack(IAsyncResult ar)
        {
            Hoofdscherm main_form = (Hoofdscherm)((object[])ar.AsyncState)[1];

            pipeServer = new NamedPipeServerStream("Drawit_pipeserver", PipeDirection.InOut, 15, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
            result     = pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnectionCallBack), new object[] { pipeServer, main_form });
            NamedPipeServerStream pipe_server = (NamedPipeServerStream)((object[])ar.AsyncState)[0];

            pipe_server.EndWaitForConnection(ar);
            StreamString ss       = new StreamString(pipe_server);
            string       filename = ss.ReadString();

            main_form.Invoke((Action) delegate { main_form.OpenFile(filename); });
            pipe_server.Close();
            pipe_server.Dispose();
        }
Esempio n. 2
0
 static void Main()
 {
     if (mutex.WaitOne(TimeSpan.Zero, true))
     {
         #region standaard
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         #endregion
         #region Culture instellen
         string cult = CultureInfo.CurrentCulture.Name;
         Thread.CurrentThread.CurrentUICulture = new CultureInfo(cult);
         Thread.CurrentThread.CurrentCulture   = new CultureInfo(cult);
         #endregion
         #region Fetch unhandled exceptions
         if (!Debugger.IsAttached)
         {
             Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
             Application.ThreadException += (sender, e) =>
             {
                 frmError frm = new frmError();
                 frm.ShowDialog(e.Exception);
             };
         }
         #endregion
         Hoofdscherm MainForm = new Hoofdscherm();
         #region PipeServer
         pipeServer = new NamedPipeServerStream("Drawit_pipeserver", PipeDirection.InOut, 15, PipeTransmissionMode.Message, PipeOptions.Asynchronous);
         result     = pipeServer.BeginWaitForConnection(new AsyncCallback(PipeConnectionCallBack), new object[] { pipeServer, MainForm });
         #endregion
         #region Cancel asynchronous operation when form closes
         ManualResetEvent signal = new ManualResetEvent(false);
         new Thread(new ParameterizedThreadStart(MonitorFormClose)).Start(signal);
         MainForm.FormClosed += delegate { signal.Set(); };
         #endregion
         #region Environment-folder
         if (!Directory.Exists(EnvironmentFolder))
         {
             Directory.CreateDirectory(EnvironmentFolder);
         }
         #endregion
         #region MainForm
         Application.Run(MainForm);
         mutex.ReleaseMutex();
         #endregion
     }
     else
     {
         try
         {
             Thread.Sleep(100);
             #region Send Filename
             NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "Drawit_pipeserver", PipeDirection.InOut, PipeOptions.None, System.Security.Principal.TokenImpersonationLevel.Impersonation);
             pipeClient.Connect(300);
             StreamString ss = new StreamString(pipeClient);
             ss.WriteString(GetFileName());
             pipeClient.Close();
             #endregion
         }
         catch (Exception)
         { }
     }
 }