Beispiel #1
0
        private async Task RunThread(ThreadTypes ThreadName, object[] objects)
        {
            DateTime dt1, dt2;

            dt1 = System.DateTime.Now;
            try
            {
                // this.SetButtonStatus(ThreadName, false);
                ThreadContext           threadContext = null;
                CancellationTokenSource tokenSource   = StartNewTask();
                ICloneable param = GetParameter(ThreadName);
                // param = DecoratorParameter(ThreadName, param, objects);
                threadContext = new ThreadContext(ThreadName, tokenSource, param);

                task = threadContext.ThreadRun();
                await task;
                //
            }
            catch (Exception ex)
            {
                //log.RecordError(ex.Message);
                //this.SetFolderButtonStatus(true);
            }
            finally
            {
                //this.SetButtonStatus(ThreadName, true);
                dt2 = System.DateTime.Now;
                //log.Log("Finished task[" + ThreadName + ". Time is " + (dt2 - dt1).ToString());
            }
        }
        public static CustomizedThread createThread(ThreadTypes ThreadName, CancellationTokenSource _tokenSource, ICloneable _threadParameter)
        {
            CustomizedThread thread = null;

            switch (ThreadName)
            {
            case ThreadTypes.UpdateBoneData:
                thread = new UpdateBoneDataThread(_tokenSource, _threadParameter);
                break;

            case ThreadTypes.WriteBoneData:
                thread = new WriteBoneDataThread(_tokenSource, _threadParameter);
                break;

            default:
                break;
            }
            return(thread);
        }
Beispiel #3
0
        private ICloneable GetParameter(ThreadTypes ThreadName)
        {
            ICloneable param = null;

            switch (ThreadName)
            {
            case ThreadTypes.UpdateBoneData:
                param = this.GetUpdateBoneDataParameter();
                break;

            case ThreadTypes.WriteBoneData:
                param = this.GetWriteBoneDataParameter();
                break;

            default:
                break;
            }
            return(param);
        }
Beispiel #4
0
        // ---------------------------------------------------------------------------------------------------------------------
        public void StartThread(ThreadTypes tnThreadType)
        {
            // Turns out that the PieChart and the TreeView were requesting StartThreads at the same time due
            // to coordinating the hover and select events of both. So now I just check if a thread is already
            // running. It's okay as they were requesting the same thing.
            if (this.IsThreadRunning())
            {
                return;
            }

            switch (tnThreadType)
            {
            case ThreadTypes.ThreadTemporaryLocate:
                this.foThread = new Thread(this.PopulateControlForTemporaryFiles);
                break;

            case ThreadTypes.ThreadTemporaryRemove:
                this.foThread = new Thread(this.foThreadRoutines.RemoveTemporaryFiles);
                break;

            case ThreadTypes.ThreadFilesViewGraph:
                this.foThread = new Thread(this.foThreadRoutines.GraphFolderSpace);
                break;
            }

            this.fnThreadType = tnThreadType;
            this.foStartTime  = DateTime.Now;

            this.foThread.Priority = ThreadPriority.Normal;

            this.foThread.Start();

            this.tmrRunning.Start();
            // Go ahead and update the time running: the timer is set at 1 second intervals
            // and therefore lags behind when the thread first starts.
            this.UpdateTimeRunningEvent(null, null);
        }
 public ThreadContext(ThreadTypes ThreadName, CancellationTokenSource _tokenSource, ICloneable _threadParameter)
 {
     superThread = ThreadFactory.createThread(ThreadName, _tokenSource, _threadParameter);
 }
Beispiel #6
0
 private async Task RunThread(ThreadTypes ThreadName)
 {
     await RunThread(ThreadName, null);
 }