本文整理汇总了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):
//.........这里部分代码省略.........