help make the program faster. at least 10 times faster
C#:
public static void Main(string[] args)
{
Task firstTask = Task.Factory.StartNew(() => InizializeCycle(Path.Combine(DesktopPath, "1.txt"), Path.Combine(DesktopPath, "01.txt")));
Console.WriteLine($"Start Task: {firstTask.Id}");
firstTask.Wait();
Task.WaitAll(firstTask);
Console.WriteLine("All threads complete");
Console.Read();
}
static readonly string CurrDir = Environment.CurrentDirectory, UserName = Environment.UserName;
static readonly string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
const int BUFFERSTREAM = 10 * 1024 * 1024;
static void InizializeCycle(string inputFile, string OutputFile)
{
if (File.Exists(inputFile))
{
try
{
using StreamReader sr = new StreamReader(new BufferedStream(File.OpenRead(inputFile), BUFFERSTREAM));
using StreamWriter sw = new StreamWriter(new BufferedStream(File.OpenWrite(OutputFile), BUFFERSTREAM));
string line = "", response = "";
while ((line = sr.ReadLine()) != null)
{
Uri url = new Uri($"...", UriKind.RelativeOrAbsolute);
response = new WebClient().DownloadString(url);
if (response.Contains("..."))
{
Console.WriteLine($"+{line}");
sw.WriteLine($"{line}");
}
else
{
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex}\r\n");
File.AppendAllText("Error_Read.txt", $"{ex}\r\n");
}
}
}