当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeServerStream.Dispose方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.Dispose方法的具体用法?C# NamedPipeServerStream.Dispose怎么用?C# NamedPipeServerStream.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeServerStream的用法示例。


在下文中一共展示了NamedPipeServerStream.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UserSignIn

        private void UserSignIn(string username, string password)
        {
            string hashed_password = sha256(password);
            MessageBox.Show(hashed_password);
            //send username and password to python and checks if correct
            string info = username + "#" + hashed_password;
            // Open the named pipe.

            var server = new NamedPipeServerStream("Communicate");
            server.WaitForConnection();     
            var br = new BinaryReader(server);
            var bw = new BinaryWriter(server); 
            send(bw, info);
            string message = recv(br); 
            server.Close();
            server.Dispose();

            //if receives true then send the user to the next gui.
            if (message == "1")
            {
                
                SaveFile form = new SaveFile();
                form.Show();

            }
            else
            {
                
                MessageBox.Show("incorrect password or username");
                this.Show();
            }
            
            
        }
开发者ID:Coby-Sonn,项目名称:coby-s-project,代码行数:34,代码来源:Form1.cs

示例2: Run

        public void Run()
        {
            while (true)
            {
                NamedPipeServerStream pipeStream = null;
                try
                {
                    pipeStream = new NamedPipeServerStream(ConnectionName, PipeDirection.InOut, -1, PipeTransmissionMode.Message);
                    pipeStream.WaitForConnection();
                    if (_stop)
                        return;

                    // Spawn a new thread for each request and continue waiting
                    var t = new Thread(ProcessClientThread);
                    t.Start(pipeStream);
                }
                catch (Exception)
                {
                    if (pipeStream != null)
                        pipeStream.Dispose();
                    throw;
                }
            }
            // ReSharper disable once FunctionNeverReturns
        }
开发者ID:lgatto,项目名称:proteowizard,代码行数:25,代码来源:RemoteService.cs

示例3: UserSignIn

        private void UserSignIn(string username, string password)
        {
            if (username == "")
            {
                MessageBox.Show("Please enter username");
                this.Show();
            }
            else if(password == "")
            {
                MessageBox.Show("Please enter password");
                this.Show();
            }
            else
            {

                string hashed_password = sha256(password);
                //send username and password to python and checks if correct
                string info = "login#" + username + "#" + hashed_password;
                // Open the named pipe.

                var server = new NamedPipeServerStream("Communicate");
                server.WaitForConnection();     
                var br = new BinaryReader(server);
                var bw = new BinaryWriter(server); 
                send(bw, info);
                string message_to_split = recv(br);
                message_to_split = message_to_split + recv(br);
                string message = message_to_split.Split('#')[0];
                if (message_to_split.Split('#')[1] != "0")
                {
                    this.my_uid = message_to_split.Split('#')[2];
                    this.firstname = message_to_split.Split('#')[1];
                    this.lastname = message_to_split.Split('#')[3];
                    MessageBox.Show(my_uid + firstname + lastname);
                }
                server.Close();
                server.Dispose();
                
                //if receives true then send the user to the next gui.
                if (message == "Signed in")
                {
                    string user_info = this.my_uid + "#" + this.firstname + "#" + this.lastname;
                    SaveFile form = new SaveFile(user_info);
                    form.Show();
                }
                else
                {
                
                    MessageBox.Show("incorrect password or username");
                    this.Show();
                }
            
            
            
            }
        }
开发者ID:Coby-Sonn,项目名称:coby-s-project,代码行数:56,代码来源:Form1.cs

示例4: PipeThread

        void PipeThread()
        {
            NamedPipeServerStream pipeServer = null;
            try
            {
                pipeServer = new NamedPipeServerStream("NowPlayingtunesSongPipe", PipeDirection.InOut);
                pipeServer.WaitForConnection();
                //When Connected
                StreamString stream = new StreamString(pipeServer);
                String playerStr = stream.ReadString();
                Debug.WriteLine("[foobar2000]Song changed.");
                Debug.WriteLine(playerStr);
                Debug.WriteLine("[foobar2000]dump end.");
                String[] playerStrSplit = playerStr.Split('\n');
                Core.iTunesClass song = new Core.iTunesClass();
                song.AlbumArtworkEnabled = false;
                song.SongTitle = playerStrSplit[0];
                song.SongAlbum = playerStrSplit[1];
                song.SongArtist = playerStrSplit[2];
                song.SongAlbumArtist = playerStrSplit[3];
                song.isFoobar = true;
                try
                {
                    song.SongTrackNumber = int.Parse(playerStrSplit[4]);
                }
                catch (Exception ex2)
                {
                }
                song.SongGenre = playerStrSplit[5];
                song.SongComposer = playerStrSplit[6];

                pipeServer.Close();
                pipeServer.Dispose();
                //適当にイベント発生させる
                onSongChangedEvent(song);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("[foobar2000] ERROR");
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                if (pipeServer != null)
                {
                    if (pipeServer.IsConnected)
                    {
                        pipeServer.Dispose();
                    }
                }
            }
            //Remake thread
            StartThread();
        }
开发者ID:kazukioishi,项目名称:NowplayingTunes,代码行数:54,代码来源:ExternalPlayerPipe.cs

示例5: Start

    // Use this for initialization
    void Start()
    {
        Debug.Log("Starting Server");
        server = new NamedPipeServerStream("NPtest");

        //Console.WriteLine("Waiting for connection...");
        Debug.Log("Waiting for connection...");
        server.WaitForConnection();

        //Console.WriteLine("Connected.");
        Debug.Log("Connected.");

        br = new BinaryReader(server);
        bw = new BinaryWriter(server);

        while (true)
        {
            try
            {
                var len = (int)br.ReadUInt32();            // Read string length
                var str = new string(br.ReadChars(len));    // Read string

                //Console.WriteLine("Read: \"{0}\"", str);
                Debug.Log(String.Format("Read: {0}", str));
                str = new string(str.Reverse().ToArray());  // Just for fun

                var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array     
                bw.Write((uint)buf.Length);                // Write string length
                bw.Write(buf);                              // Write string
                //Console.WriteLine("Wrote: \"{0}\"", str);
                Debug.Log(String.Format("Wrote: {0}", str));
            }
            catch (EndOfStreamException)
            {
                break;                    // When client disconnects
            }
        }

        //Console.WriteLine("Client disconnected.");
        Debug.Log("Client disconnected.");
        server.Close();
        server.Dispose();


    }
开发者ID:ma581,项目名称:TestingPipes,代码行数:46,代码来源:PipeWork.cs

示例6: Main

        static void Main(string[] args)
        {
            // Open the named pipe.
            var server = new NamedPipeServerStream("NPtest");

            Console.WriteLine("Waiting for connection...");
            server.WaitForConnection();

            Console.WriteLine("Connected.");
            var br = new BinaryReader(server);
            var bw = new BinaryWriter(server);

            while (true)
            {
                try
                {
                    var len = (int)br.ReadUInt32();            // Read string length
                    var str = new string(br.ReadChars(len));    // Read string

                    Console.WriteLine("Read: \"{0}\"", str);

                    str = new string(str.Reverse().ToArray());  // Just for fun

                    var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array     
                    bw.Write((uint)buf.Length);                // Write string length
                    bw.Write(buf);                              // Write string
                    Console.WriteLine("Wrote: \"{0}\"", str);
                }
                catch (EndOfStreamException)
                {
                    break;                    // When client disconnects
                }
            }

            Console.WriteLine("Client disconnected.");
            server.Close();
            server.Dispose();



        }
开发者ID:ma581,项目名称:TestingPipes,代码行数:41,代码来源:Program.cs

示例7: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            var  server = new NamedPipeServerStream("NPtest1");
               Console.WriteLine("Waiting for connection...");
               server.WaitForConnection();
               Console.WriteLine("Connected.");
               var br = new BinaryReader(server);
               var bw = new BinaryWriter(server);
               string UN = username2.Text;
               string PW = password2.Text;
               string EM = email.Text;
               string FD = folderdir.Text;
               string[] send = new string[5];
               send[0]="register";
               send[1]=UN;
               send[2]=PW;
               send[3]=EM;
               send[4]=FD;
               for(int i=0; i<send.Length;i++)

                try
                {

                     var str = new string(send[i].ToArray());  // Just for fun

                    var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array
                    bw.Write((uint)buf.Length);                // Write string length
                    bw.Write(buf);                              // Write string
                    Console.WriteLine("Wrote: \"{0}\"", str);
                }
                catch (EndOfStreamException)
                {
                    Console.WriteLine("Client disconnected.");
                    server.Close();
                    server.Dispose();   // When client disconnects
                }

                     var len2 = (int)br.ReadUInt32();            // Read string length
                     var str2 = new string(br.ReadChars(len2));    // Read string
                     MessageBox.Show(str2);
        }
开发者ID:jonathanharmatz,项目名称:Project,代码行数:41,代码来源:Form2.cs

示例8: Main

        static void Main(string[] args)
        {
            // Create a name pipe
            NamedPipeServerStream pipeStream = null;
            try
            {
                pipeStream = new NamedPipeServerStream(LogManager.ConnectionName, PipeDirection.InOut, 1, PipeTransmissionMode.Message);
                Console.WriteLine("Log Monitor started: " + pipeStream.GetHashCode());

                // Wait for a connection
                pipeStream.WaitForConnection();
                Console.WriteLine("Connection established");

                using (StreamReader sr = new StreamReader(pipeStream))
                {
                    pipeStream = null;

                    string temp;
                    // We read a line from the pipe and print it together with the current time
                    while ((temp = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(temp);
                    }
                }
            }
            finally
            {
                if (pipeStream != null)
                {
                    pipeStream.Dispose();
                }
            }

            Console.WriteLine("Connection lost");
            Console.WriteLine("Press <ENTER> to quit");
            Console.ReadLine();
        }
开发者ID:dhanzhang,项目名称:Windows-classic-samples,代码行数:37,代码来源:Program.cs

示例9: StartPipeServer

        public void StartPipeServer()
        {
            serverStream = new NamedPipeServerStream("zjlrcpipe",
                PipeDirection.InOut,
                10,
                PipeTransmissionMode.Message,
                PipeOptions.None);
            serverStream.ReadMode = PipeTransmissionMode.Message;
            Byte[] bytes = new Byte[1024];
            UTF8Encoding encoding = new UTF8Encoding();
            int numBytes;
            while (running)
            {

                serverStream.WaitForConnection();
                string message = "";
                do
                {
                    numBytes = serverStream.Read(bytes, 0, bytes.Length);

                    message += encoding.GetString(bytes, 0, numBytes);
                } while (!serverStream.IsMessageComplete);

                string[] pas = message.Split('|');
                if (null != pas && pas.Length >= 3)
                {
                    if (!(pas[0] == "exit" && pas[1] == "exit" && pas[2] == "exit"))
                        main.Dispatcher.Invoke(main.searchLrcByZLP, pas[0], pas[1], pas[2]);
                    else
                        running = false;
                }

                serverStream.Disconnect();

            }
            serverStream.Dispose();
        }
开发者ID:zhaojunlucky,项目名称:Audio,代码行数:37,代码来源:PipeServer.cs

示例10: StartListen

        public void StartListen(NamedPipeServerStream pipeServer)
        {
            if (_stopListen)
            {
                if (pipeServer != null)
                    pipeServer.Dispose();
                return;
            }

            try
            {
                if (pipeServer == null)
                {
                    pipeServer = new NamedPipeServerStream(PipeName, PipeDirection.InOut, NumberOfPipeInst,
                                  PipeTransmissionMode.Byte, PipeOptions.WriteThrough | PipeOptions.Asynchronous);
                }

                pipeServer.BeginWaitForConnection(OnConnectToClient, pipeServer);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:sargiss,项目名称:HookLibrary,代码行数:24,代码来源:PipeChannel.cs

示例11: DoEncode


//.........这里部分代码省略.........
                }

                startTime = DateTime.Now;

                if (started && decStarted)
                {
                    encoder.PriorityClass = AppSettings.GetProcessPriority();
                    encoder.BeginErrorReadLine();
                    decoder.PriorityClass = AppSettings.GetProcessPriority();
                    decoder.BeginErrorReadLine();

                    Thread pipeReadThread = new Thread(() =>
                        {
                            try
                            {
                                ReadThreadStart(decodePipe, encoder);
                            }
                            catch (Exception ex)
                            {
                                Log.Error(ex);
                            }
                        });
                    pipeReadThread.Start();
                    pipeReadThread.Priority = ThreadPriority.BelowNormal;
                    encoder.Exited += (o, args) => pipeReadThread.Abort();

                    while (!encoder.HasExited)
                    {
                        if (_bw.CancellationPending)
                        {
                            encoder.Kill();
                            decoder.Kill();
                        }
                        Thread.Sleep(200);
                    }

                    encoder.WaitForExit(10000);
                    encoder.CancelErrorRead();

                    if (decodePipe.IsConnected)
                        try
                        {
                            decodePipe.Disconnect();
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex);
                        }

                    try
                    {
                        decodePipe.Close();
                        decodePipe.Dispose();
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }

                    decoder.WaitForExit(10000);
                    decoder.CancelErrorRead();

                    _jobInfo.ExitCode = encoder.ExitCode;
                    Log.InfoFormat("Exit Code: {0:g}", _jobInfo.ExitCode);
                }
            }

            if (_jobInfo.ExitCode == 0)
            {
                if ((encProfile.EncodingMode == 1 && _jobInfo.StreamId == 2) ||
                    encProfile.EncodingMode == 0)
                {
                    _jobInfo.VideoStream.Encoded = true;
                    _jobInfo.VideoStream.IsRawStream = false;

                    _jobInfo.TempFiles.Add(_jobInfo.VideoStream.TempFile);
                    _jobInfo.VideoStream.TempFile = outFile;

                    try
                    {
                        _jobInfo.MediaInfo = Processing.GetMediaInfo(_jobInfo.VideoStream.TempFile);
                    }
                    catch (TimeoutException ex)
                    {
                        Log.Error(ex);
                    }
                    _jobInfo.VideoStream = VideoHelper.GetStreamInfo(_jobInfo.MediaInfo, _jobInfo.VideoStream, _jobInfo.EncodingProfile.OutFormat == OutputType.OutputBluRay);

                    string statsFile = Processing.CreateTempFile(outFile, "stats");
                    _jobInfo.TempFiles.Add(statsFile);
                    _jobInfo.TempFiles.Add(_jobInfo.AviSynthScript);
                    _jobInfo.TempFiles.Add(_jobInfo.FfIndexFile);
                    _jobInfo.TempFiles.Add(_jobInfo.AviSynthStereoConfig);
                }
            }

            _bw.ReportProgress(100);
            _jobInfo.CompletedStep = _jobInfo.NextStep;
            e.Result = _jobInfo;
        }
开发者ID:jesszgc,项目名称:VideoConvert,代码行数:101,代码来源:VpxEnc.cs

示例12: ReadPythonPipe

        static string ReadPythonPipe(NamedPipeServerStream server)
        {
            

            //Reading
            var br = new BinaryReader(server);
            var bw = new BinaryWriter(server);

            while (true)
            {
                try
                {
                    var len = (int)br.ReadUInt32();            // Read string length
                    //Console.WriteLine("Length: {0}", len.ToString());
                    var str = new string(br.ReadChars(len));    // Read string

                    Console.WriteLine("Read: \"{0}\"", str);

                    //str = new string(str.Reverse().ToArray());  // Just for fun

                    //var buf = Encoding.ASCII.GetBytes(str);     // Get ASCII byte array     
                    //bw.Write((uint)buf.Length);                // Write string length
                    //bw.Write(buf);                              // Write string
                    //Console.WriteLine("Wrote: \"{0}\"", str);

                    //for (int i=0; i<data.Length; i++)
                    //{
                    //    return data[i];
                    //}
                    //char[] data = str.ToCharArray;
                    string data = str;
                    return data;

                }
                catch (EndOfStreamException)
                {
                    break;                    // When client disconnects
                }
            }

            Console.WriteLine("Client disconnected.");
            server.Close();
            server.Dispose();

            //char[] empty = null;
            string empty = null;
            return empty; 
            


        }
开发者ID:ma581,项目名称:TestingPipes,代码行数:51,代码来源:Program.cs

示例13: AddUser

        private void AddUser(string firstname, string lastname, string username, string password, string confirmPass)
        {
            string pattern = @"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.* ).{8,15}$";
            
            //asks the database if the username exists already
            if (password != confirmPass)
            {
                MessageBox.Show("Passwords do not match");
            }
            else if (!Regex.IsMatch(password, pattern))
            {
                MessageBox.Show(password);
                
                MessageBox.Show("Password must be between 8-15 characters and must contain at least one uppercase letter, one lowercase letter, one number and no special characters besides space");
            }
            //Password must be at least 8 characters long
            else if (password.Length < 8)
            {
                MessageBox.Show("Password must be at least 8 characters long");
            }
            else if (username == null || username.Length < 2 || username.Length > 15)
            {
                MessageBox.Show("Username missing or too short");
            }
            else if (firstname == null || firstname.Length < 2)
            {
                MessageBox.Show("First name missing or too short");
            }
            else if (lastname == null || lastname.Length < 2)
            {
                MessageBox.Show("Last name missing or too short");
            }
            else
            {
                this.Hide();
                Random rnd = new Random();
                int uid = rnd.Next(10000000, 99999999);
                string UID = uid.ToString();
                string hashed_password = sha256(password);
                string information_string = "register#" + UID + "#" + firstname + "#" + lastname + "#" + username + "#" + hashed_password;
                //send python all the information for registration

                var server = new NamedPipeServerStream("Communicate");
                server.WaitForConnection();
                var br = new BinaryReader(server);
                var bw = new BinaryWriter(server);
                send(bw, information_string);
                string message = recv(br);
                server.Close();
                server.Dispose();
                if (message == "Signed up")
                {
                    MessageBox.Show("User Signed Up");
                }
                else if (message == "username exists")
                {
                    this.Show();
                    MessageBox.Show("Username already exists");

                }
                
            }
    
        }
开发者ID:Coby-Sonn,项目名称:coby-s-project,代码行数:64,代码来源:Form1.cs

示例14: pipeWorker_DoWork

        void pipeWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var server = new NamedPipeServerStream("alotPipe");

                updateStatus("Waiting for connection from alot.py...");
                server.WaitForConnection();

                updateStatus("");
                var br = new BinaryReader(server);
                var bw = new BinaryWriter(server);

                while (true)
                {
                    try
                    {
                        var len = (int)br.ReadUInt32();
                        var msg = new string(br.ReadChars(len));

                        //write received message to file (for debugging purposes)
                        StreamWriter file = new StreamWriter(Application.StartupPath + "\\last received message.txt");
                        file.WriteLine(msg);
                        file.Close();

                        processMsg(msg);
                    }
                    catch (EndOfStreamException)
                    {
                        break;
                    }
                }

                server.Close();
                server.Dispose();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Exception in pipeWorker_DoWork(): " + exc.Message);
            }
        }
开发者ID:Winterstark,项目名称:Alot-of-Knowledge,代码行数:41,代码来源:formMain.cs

示例15: sendFeedbackToAlot

        void sendFeedbackToAlot(string feedback)
        {
            try
            {
                var server = new NamedPipeServerStream("alotPipeFeedback");
                server.WaitForConnection();

                var bw = new BinaryWriter(server);
                if (feedback == "True")
                    bw.Write(true);
                else
                    bw.Write(feedback);

                server.Close();
                server.Dispose();
            }
            catch (Exception exc)
            {
                MessageBox.Show("Error while sending feedback!" + Environment.NewLine + exc.Message + Environment.NewLine + Environment.NewLine + "Trying again...");
                sendFeedbackToAlot(feedback);
            }
        }
开发者ID:Winterstark,项目名称:Alot-of-Knowledge,代码行数:22,代码来源:formMain.cs


注:本文中的System.IO.Pipes.NamedPipeServerStream.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。