Exemple #1
0
        // global verbosity rules will be applied

        public static void Write(string data, int verbosity = Verbosity.Verbose, int tid = 0)
        {
            if ((COptions.Verbosity != 0) && (verbosity <= COptions.Verbosity))
            {
                // create temp path on first write
                CFunctions.CreateFolderIfNotExist(TempPath);

                // create log file on first write
                string strLogFile = TempPath + "\\" + ProductName + ".log";
                CFunctions.CreateFileIfNotExist(strLogFile);

                if (tid == 0)
                {
                    tid = System.Threading.Thread.CurrentThread.ManagedThreadId;
                }
                Process currentProcess = Process.GetCurrentProcess();
                int     pid            = currentProcess.Id;

                // write data to log
                // could make faster by turning into in-memory queueing system that then writes to log
                lock (_LogWriterLock)
                {
                    TextWriter logFile = new StreamWriter(strLogFile, true);
                    logFile.WriteLine("[" + CFunctions.GetDateTime(CFunctions.DateFormatLogging) + "] <" + pid + ":" + tid + "> " + data);
                    logFile.Close();
                }
            }
        }
 public CThread()
 {
     if (Type == null)
     {
         Type = new CThread.Types(Types.Unmanaged);
     }
     if (Id.Length == 0)
     {
         Id = CFunctions.GenerateUID();
     }
 }
        // zzz - need to improve http://stackoverflow.com/questions/8028483/managing-threads-using-listthread

        public CThreadManager()
        {
            // start session manager thread
            Thread.CurrentThread.Name = CFunctions.GenerateUID();
            ThreadManager             = new CThread()
            {
                Worker = new Thread(new ThreadStart(ManageThreads))
            };
            Log.Write("[Threading] Primary thread (" + Thread.CurrentThread.Name + ") of type: '" + ThreadManager.Type + "' with scheduler id: " + Thread.CurrentThread.ManagedThreadId + " started at: " + Core._StartTime, 7);
            ThreadManager.Start();
            Log.Write("[Threading] Starting new thread (" + ThreadManager.Id + ") of type: '" + ThreadManager.Type + "' with scheduler id: " + ThreadManager.Worker.ManagedThreadId, 7);
        }