Ejemplo n.º 1
0
    public static void StartBroadcast()
    {
        CancellationToken token = cancelTokenSource.Token;
        Task task = new Task(() =>
        {
            Task <string> task1 = outstr.ReadLineAsync();
            Task <string> task2 = errorstr.ReadLineAsync();
            while (!token.IsCancellationRequested)
            {
                if (task1.IsCompleted)
                {
                    string temp = task1.Result;

                    if (ProcessCMD.dirsync)
                    {
                        ProcessCMD.SetCurrentDirectory(temp);
                        ProcessCMD.dirsync = false;
                    }
                    else if (ProcessCMD.exec)
                    {
                        outstr.ReadLine();
                        ProcessCMD.exec = false;
                    }
                    else
                    {
                        SendToAll(Encoding.ASCII.GetBytes(task1.Result + "\r\n"));
                    }
                    task1 = outstr.ReadLineAsync();
                }
                else if (task2.IsCompleted)
                {
                    SendToAll(Encoding.ASCII.GetBytes(task2.Result + "\r\n"));
                    task2 = errorstr.ReadLineAsync();
                }
            }
        });

        task.Start();
    }