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


C# Channel.WriteData方法代码示例

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


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

示例1: RunClient

        private void RunClient(NetworkStream clientStream)
        {
            Channel channel;
            byte signal;
            Job currentJob = null;
            int pointNumber = 0;
            using (BinaryReader reader = new BinaryReader(clientStream))
            {
                using (BinaryWriter writer = new BinaryWriter(clientStream))
                {
                    channel = new Channel(reader, writer, true);

                    while (true)
                    {
                        try
                        {
                            signal = channel.ReadData(typeof(byte));

                            switch (signal)
                            {
                                case ((byte)Constants.RecieveTask):

                                    currentJob = (Job)channel.ReadObject();
                                    pointNumber = channel.ReadData(typeof(int));
                                    _jobPointNumberDictionary.AddOrUpdate(currentJob.Number, new List<int> { pointNumber },
                                        (key, oldvalue) =>
                                        {
                                            oldvalue.Add(pointNumber);
                                            return oldvalue;
                                        });
                                    _cancellationDictionary.AddOrUpdate(currentJob.Number, new CancellationTokenSource(),
                                        (key, oldValue) => oldValue);
                                    continue;

                                case ((byte)Constants.ExecuteClass):

                                    if (currentJob != null)
                                    {
                                        var cancellationTokenSource = _cancellationDictionary[currentJob.Number];
                                        if (!_cancellationDictionary[currentJob.Number].IsCancellationRequested)
                                        {
                                            var executor = new ModuleExecutor(channel, currentJob, pointNumber);

                                            try
                                            {
                                                executor.Run(cancellationTokenSource.Token);
                                            }
                                            catch (OperationCanceledException)
                                            {
                                                _log.Info($"Point N {currentJob.Number}:{pointNumber} was cancelled");
                                            }

                                            DeletePoint(currentJob.Number, pointNumber);

                                            if (_jobPointNumberDictionary[currentJob.Number].Count == 0)
                                            {
                                                lock (_locker)
                                                {
                                                    if (File.Exists(currentJob.FileName))
                                                    {
                                                        File.Delete(currentJob.FileName);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    return;

                                case ((byte)Constants.LoadFile):
                                    {
                                        LoadFile(channel, currentJob);
                                        continue;
                                    }

                                case ((byte)Constants.ProcessorsCountRequest):
                                    {
                                        channel.WriteData(Environment.ProcessorCount);
                                        continue;
                                    }

                                case ((byte)Constants.LinpackRequest):
                                    {
                                        var linpack = new Linpack();
                                        linpack.RunBenchmark();
                                        channel.WriteData(linpack.MFlops);
                                        continue;
                                    }

                                case ((byte)Constants.ServerIP):
                                    {
                                        string ip = channel.ReadData(typeof(string));
                                        if (_server == null || _server.IpAddress.ToString() != ip)
                                        {
                                            _server = new HostInfo(ip, (int)Ports.ServerPort);
                                        }

                                        continue;
                                    }
                                case ((byte)Constants.CancelJob):
//.........这里部分代码省略.........
开发者ID:AndriyKhavro,项目名称:Parcs.NET,代码行数:101,代码来源:Daemon.cs


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