예제 #1
0
        private void ServerThread()
        {
            while (true)
            {
                string text;
                using (var server = new NamedPipeServerStream(_UID))
                {
                    server.WaitForConnection();

                    using (StreamReader reader = new StreamReader(server))
                    {
                        text = reader.ReadToEnd();
                    }
                }

                if (text == EXIT_STRING)
                {
                    break;
                }

                ReceiveString?.Invoke(text);
                if (_isRunning == false)
                {
                    break;
                }
            }
        }
예제 #2
0
 void GenericEvent(ReceiveString func, string msg)
 {
     if (func != null)
     {
         func.Invoke(msg);
     }
 }
예제 #3
0
        /// <summary>
        /// Returns the message recieved and spawns a new server disposing of the previous backgroundworker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            string result = e.Result as string;

            if (result != EXIT_STRING)
            {
                StartServer();                 //If not exit then start a new server instance
                ReceiveString?.Invoke(result); //Send signal we've received a new file to open
            }

            //Dispose background worker
            BackgroundWorker bw = (sender as BackgroundWorker);

            bw.RunWorkerCompleted -= Bw_RunWorkerCompleted;
            bw.DoWork             -= Bw_DoWork;
            Task.Run(() => bw.Dispose());
        }
			private void OnReceiveString(string text) => ReceiveString?.Invoke(text);
예제 #5
0
 /// <summary>
 /// Called when data is received.
 /// </summary>
 /// <param name="text"></param>
 protected virtual void OnReceiveString(string text) => ReceiveString?.Invoke(text);
예제 #6
0
 private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
 {
     ReceiveString?.Invoke(e.UserState as string);
 }