Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Diagnostics;
  8. using System.Threading;
  9.  
  10.  
  11. namespace Logi
  12. {
  13.     class Program
  14.     {
  15.         public static Process MyProcess = new Process();
  16.         public static int nProcessID = Process.GetCurrentProcess().Id;
  17.         static void Main(string[] args)
  18.         {
  19.             Console.Title = "Wpisujemy logi. Id procesu: " + nProcessID.ToString();    
  20.             Linie.Dopisywanie();          
  21.             Console.ReadKey();
  22.         }
  23.     }
  24.  
  25.     class Linie : Program
  26.     {
  27.         static string path = @"C:\Users\matis\Desktop\test.log";
  28.         static DateTime aktualnaData = DateTime.Now;
  29.         private static Mutex mut = new Mutex();
  30.  
  31.  
  32.         public static void Dopisywanie()
  33.         {
  34.             mut.WaitOne();
  35.             try
  36.             {
  37.                 using (StreamWriter sw = new StreamWriter(path, true))
  38.  
  39.                 {
  40.  
  41.                     for (int i = 0; i < 100; i++)
  42.                     {
  43.                         sw.WriteLine("{0}; Id \t {1}; Time {2}", i, nProcessID.ToString(), aktualnaData);
  44.                         Thread.Sleep(100);
  45.                         Postep(i);
  46.                     }
  47.                     Console.SetCursorPosition(0, 1);
  48.                     Console.WriteLine("Koniec");
  49.  
  50.                 }
  51.             }
  52.             catch
  53.             {
  54.                 Console.WriteLine("Czekam");
  55.  
  56.             }
  57.             finally
  58.             {
  59.                 mut.ReleaseMutex();
  60.             }
  61.  
  62.         }
  63.         public static void Postep(int x)
  64.         {
  65.             Console.SetCursorPosition(0, 0);
  66.             Console.WriteLine("Wpisuje {0}", string.Concat(Enumerable.Repeat(".", x)));
  67.  
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement