Перевод из консольного приложения в форму - C#
Формулировка задачи:
Здравствуйте
Помогите,пожалуйста,перевести консольное приложение в форму.
вот код программы в консоле
При переводе застрял на функции static void research()
class StrSearch
{
public static string FilePatch;
static string Str;
static int StrCount;
static string FileSize;
static string GetSizeInString(string FilePatch)
{
System.IO.FileInfo File = new System.IO.FileInfo(FilePatch);
long size = File.Length;
string[] postfix = { "байт", "Kb", "Mb", "Gb", "Tb" };
int i = 1;
double temp = (double)size;
while ((temp /= 1024) > 1024 && i++ < postfix.Length) ;
return String.Format("{0:F}", temp) + " " + postfix[i];
}
static int GetLineString(string FilePatch)
{
int StrCount = 0;
using (FileStream fStream = new FileStream(FilePatch, FileMode.Open))
{
if (fStream.Length != 0)
{
int b;
StrCount = 1;
while ((b = fStream.ReadByte()) != -1)
{
if (b == 10)
{
++StrCount;
}
}
}
}
return StrCount;
}
static void Main(string[] args)
{
Process thisProc = Process.GetCurrentProcess();
thisProc.PriorityClass = ProcessPriorityClass.RealTime;
//Console.WriteLine("Enter File:");
FilePatch = @"1.txt";
Console.WriteLine("Enter Str:");
Str = Console.ReadLine();
// Create new stopwatch
Stopwatch stopwatch = new Stopwatch();
// Begin timing
stopwatch.Start();
StrCount = GetLineString(FilePatch);
FileSize = GetSizeInString(FilePatch);
Console.Clear();
Console.Write(" [" + FilePatch + " = " + StrCount + " str, " + FileSize + "]");
int ThreadsCount = 1;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread[] ThreadS;
ThreadS = new Thread[ThreadsCount];
for (int i = 0; i < ThreadsCount; i++)
{
ThreadS[i] = new Thread((research)); ThreadS[i].Start();
}
// Stop timing
stopwatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopwatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);
Console.WriteLine("\n RunTime " + elapsedTime);
}
static void research()
{
while (true)
{
try
{
var StrLine = new StrSearchC();
if (StrLine.Contains(Str) == true)
Console.Write("\n [Found]: " + Str);
else if (StrLine.Contains(Str) == false)
Console.Write("\n [Not Found]: " + Str);
Console.Write("\n Нажмите любую клавишу для завершения.....");
Console.ReadLine();
Console.Clear();
break;
}
catch (ThreadAbortException)
{
break;
}
catch (Exception ex)
{
continue;
}
}
}
}
class StrSearchC
{
private HashSet<string> StrTable;
public StrSearchC()
{
var StrSearchNumbersFromFile = File.ReadLines(StrSearch.FilePatch);
StrTable = new HashSet<string>(StrSearchNumbersFromFile);
}
public bool Contains(string value)
{
return StrTable.Contains(value);
}
}Решение задачи: «Перевод из консольного приложения в форму»
textual
Листинг программы
Process thisProc = Process.GetCurrentProcess(); thisProc.PriorityClass = ProcessPriorityClass.RealTime;