class Program
{
static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();
Console.ReadKey();
}
static async Task MainAsync(string[] args)
{
HardWorker hardWorker1 = new HardWorker();
HardWorker hardWorker2 = new HardWorker();
HardWorker hardWorker3 = new HardWorker();
HardWorker hardWorker4 = new HardWorker();
HardWorker hardWorker5 = new HardWorker();
Task t1 = Task.CompletedTask;
Task t2 = Task.CompletedTask;
Task t3 = Task.CompletedTask;
Task t4 = Task.CompletedTask;
Task t5 = Task.CompletedTask;
Random rand = new Random();
for (int i = 0; i < 50; i++)
{
t1 = t1.ContinueWith(task => hardWorker1.DoSomething(1, rand.Next(1, 10000)));
t2 = t2.ContinueWith(task => hardWorker2.DoSomething(2, rand.Next(1, 10000)));
t3 = t3.ContinueWith(task => hardWorker3.DoSomething(3, rand.Next(1, 10000)));
t4 = t4.ContinueWith(task => hardWorker4.DoSomething(4, rand.Next(1, 10000)));
t5 = t5.ContinueWith(task => hardWorker5.DoSomething(5, rand.Next(1, 10000)));
}
await Task.WhenAll(t1, t2, t3, t4, t5);
}
}
public class HardWorker : AbstractHardWorker
{
public void DoSomething(int task, int time)
{
Console.Out.WriteLine("Start: " + task);
Thread.Sleep(time);
Console.Out.WriteLine("End: " + task);
}
}
public interface AbstractHardWorker
{
void DoSomething(int task, int time);
}
var bytes1 = new byte[writeStream.Length];
writeStream.Read(bytes1, 0, bytes1.Length);
writer.Write(bytes1, 0, bytes1.Length);
writeStream.Position = 0;
writeStream.CopyTo(writer);
IIssueService
, в который перенести методы AcceptToWork
, Close
и т.д., которые будут принимать на вход ту Issue, над которой выполняется действие.IIssueService
различными менеджерами типа IConfigurationManager
и IDateTimeProvider
. throw;
) или в обёртке из business-specific исключения: try
{
return int.Parse(stringValue);
}
catch (FormatException ex)
{
Logger.Error(ex);
throw new MyParserException($"Неверный формат числа {stringValue}", ex);
}
catch (OverflowException ex)
{
Logger.Error(ex);
throw new MyParserException($"Выход за допустимый диапазон {stringValue}", ex);
}
. var secondFileLines = new HashSet<string>(File.ReadLines("<файл2>"));
using (var writer = new StreamWriter("<файл3>"))
{
foreach (var line in File.ReadLines("<файл1>"))
{
if (!secondFileLines.Contains(line))
{
writer.WriteLine(line);
}
}
}
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "mystem.exe";
p.StartInfo.Arguments = "-n input.txt";
p.Start();
using (var reader = new StreamReader(p.StandardOutput.BaseStream, Encoding.UTF8))
{
textBox3.Text = reader.ReadToEnd();
}
p.WaitForExit();