Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Diagnostics;
- using System.Threading;
- namespace Logi
- {
- class Program
- {
- public static Process MyProcess = new Process();
- public static int nProcessID = Process.GetCurrentProcess().Id;
- static void Main(string[] args)
- {
- Console.Title = "Wpisujemy logi. Id procesu: " + nProcessID.ToString();
- Linie.Dopisywanie();
- Console.ReadKey();
- }
- }
- class Linie : Program
- {
- static string path = @"C:\Users\matis\Desktop\test.log";
- static DateTime aktualnaData = DateTime.Now;
- private static Mutex mut = new Mutex();
- public static void Dopisywanie()
- {
- mut.WaitOne();
- try
- {
- using (StreamWriter sw = new StreamWriter(path, true))
- {
- for (int i = 0; i < 100; i++)
- {
- sw.WriteLine("{0}; Id \t {1}; Time {2}", i, nProcessID.ToString(), aktualnaData);
- Thread.Sleep(100);
- Postep(i);
- }
- Console.SetCursorPosition(0, 1);
- Console.WriteLine("Koniec");
- }
- }
- catch
- {
- Console.WriteLine("Czekam");
- }
- finally
- {
- mut.ReleaseMutex();
- }
- }
- public static void Postep(int x)
- {
- Console.SetCursorPosition(0, 0);
- Console.WriteLine("Wpisuje {0}", string.Concat(Enumerable.Repeat(".", x)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement