Ejemplo n.º 1
0
        private void DecodeFileOnSeparateThread(PFFileEncoder encoder, string encryptedInputFile, string tempFileName, StatusTimer st)
        {
            TimeSpan      ts    = new TimeSpan(0, 0, _statusReportIntervalSeconds);
            PFThread      t     = new PFThread(new ParameterizedThreadStart(DecodeFileFromBase64), "DecodeFileFromBase64");
            List <object> parms = new List <object>();

            parms.Add(encoder);
            parms.Add(encryptedInputFile);
            parms.Add(tempFileName);
            parms.Add(st);
            t.ThreadDescription       = "Decode File from Base64 Text.";
            t.ShowElapsedMilliseconds = false;
            t.StartTime = DateTime.Now;
            st.ShowElapsedTimeMilliseconds = false;
            st.NumSecondsInterval          = _statusReportIntervalSeconds;
            if (st.StatusTimerIsRunning == false)
            {
                st.Start();
            }
            t.Start(parms);
            while (t.ThreadObject.Join(ts) == false)
            {
                if (st.StatusReportDue())
                {
                    FileInfo fi = new FileInfo(tempFileName);
                    currentStatusReport("DecodeEncryptionFromBase64", "InProgress", fi.Length, (int)st.GetElapsedTime().TotalSeconds, st.GetFormattedElapsedTime());
                    fi = null;
                }
            }
            t.FinishTime = DateTime.Now;
        }
Ejemplo n.º 2
0
        //methods

        private void InitializeThread(object parameter)
        {
            if (_taskToRun == null)
            {
                _msg.Length = 0;
                _msg.Append("You must specify a Task object for the the processor to use. TaskToRun property is null.");
                throw new System.Exception(_msg.ToString());
            }
            if (String.IsNullOrEmpty(_taskToRun.FileToRun.Trim()))
            {
                _msg.Length = 0;
                _msg.Append("You must specify a file to run. FileToRun property is empty.");
                throw new System.Exception(_msg.ToString());
            }

            string threadName        = _taskToRun.TaskName;
            string threadDescription = "Thread for " + _taskToRun.TaskName;

            if (parameter == null)
            {
                _t = new PFThread(new ThreadStart(TaskEntryPoint), threadName);
            }
            else
            {
                _t = new PFThread(new ParameterizedThreadStart(TaskEntryPointWithParameter), threadName);
            }
            _t.ThreadDescription = threadDescription;


            _t.HasFinished = false;
            _t.StartTime   = DateTime.Now;
        }
Ejemplo n.º 3
0
        //methods

        private void InitializeThread(object parameter)
        {
            string threadName        = "Thread_" + _taskName;
            string threadDescription = "Thread for " + _taskDescription;

            if (parameter == null)
            {
                _t = new PFThread(new ThreadStart(TaskEntryPoint), threadName);
            }
            else
            {
                _t = new PFThread(new ParameterizedThreadStart(TaskEntryPointWithParameter), threadName);
            }
            _t.ThreadDescription = threadDescription;

            string logfile = FormatLogFilePath(this.LogFolder, this.TaskName + ".log");

            if (this.UseSharedLogFile)
            {
                _log.OpenFile(logfile, PFFileOpenOperation.OpenFileForAppend);
            }
            else
            {
                _log.OpenFile(logfile, PFFileOpenOperation.OpenFileForWrite);
            }

            _t.HasFinished = false;
            _t.StartTime   = DateTime.Now;
        }
Ejemplo n.º 4
0
        public static void PFThreadTest()
        {
            Stopwatch sw = new Stopwatch();

            try
            {
                sw.Start();

                _msg.Length = 0;
                _msg.Append("PFThreadTest started ...");
                Program._messageLog.WriteLine(_msg.ToString());

                _msg.Length = 0;
                _msg.Append("Calling thread is ");
                _msg.Append(Thread.CurrentThread.ManagedThreadId.ToString());
                _msg.Append(".");
                Program._messageLog.WriteLine(_msg.ToString());
                Console.WriteLine(_msg.ToString());

                //PFThread t = new PFThread(new ThreadStart(EntryPointForThreadTest), "TestThread1");
                PFThread t = new PFThread(new ThreadStart(EntryPointForThreadTest));

                t.ThreadDescription       = "Thread run by PFThreadTest method.";
                t.ShowElapsedMilliseconds = true;

                t.StartTime = DateTime.Now;
                t.Start();

                //t.ThreadObject.Join();   //blocking

                //Thread.Sleep(100);  //give it time to make sure thread has started
                //while (t.IsAlive == true)
                //{
                //    Thread.Sleep(1000);
                //}

                while (t.ThreadObject.Join(TimeSpan.Zero) == false)
                {
                    Thread.Sleep(1000);
                }

                t.FinishTime = DateTime.Now;

                _msg.Length = 0;
                _msg.Append("Thread run time: ");
                _msg.Append(t.ElapsedTimeFormatted);
                Program._messageLog.WriteLine(_msg.ToString());
                Console.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("... PFThreadTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());

                sw.Stop();
                _msg.Length = 0;
                _msg.Append("Total run time: \r\n");
                _msg.Append(sw.FormattedElapsedTime);
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }