public static void Main(string[] args)
        {

            _CurrentProperty = ThreadProperties.FromCurrentThread();

            using (var mutex = new Mutex(false, "MusicCollection SingleApplication"))
            {
                // Wait a few seconds if contended, in case another instance
                // of the program is still in the process of shutting down.
                if (!mutex.WaitOne(TimeSpan.FromSeconds(3), false))
                {
                    Trace.WriteLine("Another instance of the MusicCollection is running!");

                    if (ApplicationDeployment.IsNetworkDeployed)
                    {
                        string activationData = GetInputFilePath();
                        if (activationData != null)
                        {
                            try
                            {
                                IMusicFileImporter imf = new IPCClient<IMusicFileImporter>().GetService();
                                imf.ImportCompactedFileAsync(activationData).Wait();
                            }
                            catch { }
                        }
                    }

                    return;
                }

                Execute(args);
            }
        }
        public void TD()
        {
            Init();

            
            
            ThreadProperties TP = new ThreadProperties( ThreadPriority.Highest,ProcessPriorityClass.High);
            TP.SetCurrentThread();

            //Thread.CurrentThread.Priority = ThreadPriority.Highest;
            //Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;

            var tr2 = TimeTracer.TimeTrack("Session Building");
            using (tr2)
            {
                _MS = MusicSessionImpl.GetSession(_SK.Builder);
                _msi = _MS as MusicSessionImpl;
                GC.Collect();
                GC.WaitForFullGCComplete();
            }

            _BuildSessionTime = (TimeSpan)tr2.EllapsedTimeSpent;

            Assert.That(_MS.AllAlbums.Count, Is.EqualTo(0));
            Assert.That(_MS.AllGenres.Count, Is.EqualTo(0));
            Assert.That(_MS.AllArtists.Count, Is.EqualTo(0));



            var tr = TimeTracer.TimeTrack("Load before vacuum");
            using (tr)
            {
                IMusicImporter imi = _MS.GetDBImporter();
                Assert.That(imi, Is.Not.Null);
                imi.Load();
            }

            _OpenTime = (TimeSpan)tr.EllapsedTimeSpent;


            Assert.That(_MS.AllAlbums.Count, Is.EqualTo(_AlbumNumber));
            Assert.That(_MS.AllArtists.Count, Is.EqualTo(_ArtistNumber));

            GC.Collect();
            GC.WaitForFullGCComplete();
        }
        static public Task LoadAsync(ThreadProperties tp = null)
        {
            if (_Loader != null)
                return _Loader;

            _Loader = Task.Factory.StartNew(
                () =>
                {
                    using (tp.GetChanger())
                    {
                        PythonEvaluator = new PythonEvaluator();
                    }
                }, 
                CancellationToken.None,
                TaskCreationOptions.LongRunning, 
                TaskScheduler.Default);

            return _Loader;
        }
        public void FromCurrentThread_Test()
        {
         

            ThreadPriority or = Thread.CurrentThread.Priority;

            if (or == ThreadPriority.Highest)
            {
                Thread.CurrentThread.Priority = ThreadPriority.Normal;
            }  
            
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Normal;
            
            ThreadProperties target = ThreadProperties.FromCurrentThread();
            target.Should().NotBeNull();

            or = Thread.CurrentThread.Priority;
            or.Should().NotBe(ThreadPriority.Highest);

            ProcessPriorityClass orproc = Process.GetCurrentProcess().PriorityClass;
            orproc.Should().NotBe(ProcessPriorityClass.High);

            target.ProcessPriorityClass.Should().Be(orproc);
            target.ThreadPriority.Should().Be(or);


            ThreadProperties targetprop = new ThreadProperties(ThreadPriority.Highest, null);

            using (targetprop.GetChanger())
            {
                Thread.CurrentThread.Priority.Should().Be(ThreadPriority.Highest);
                Process.GetCurrentProcess().PriorityClass.Should().Be(orproc);
            }

            Thread.CurrentThread.Priority.Should().Be(or);
            Process.GetCurrentProcess().PriorityClass.Should().Be(orproc);
   
        }
 Task IMusicImporter.LoadAsync(ThreadProperties tp)
 {
     return UniversalLoadAsync(null, CancellationToken.None, tp);
 }
 private Task UniversalLoadAsync(IImportExportProgress iIImportProgress, CancellationToken? iCancelationToken, ThreadProperties tp)
 {
     return Task.Factory.StartNew(
        () =>
        {
            using (tp.GetChanger())
            {
                SecureImport(iIImportProgress, iCancelationToken);
            }
        },
         CancellationToken.None,
         TaskCreationOptions.LongRunning,
         TaskScheduler.Default);
 }
        static async private void slaphscreen_Loaded(object sender, RoutedEventArgs e)
        {
            ThreadProperties TP = new ThreadProperties(ThreadPriority.Highest, null);

            new ThreadProperties(ThreadPriority.Normal, ProcessPriorityClass.High).SetCurrentThread();

            using (var tt = TimeTracer.TimeTrack("Load Time"))
            {
                IMusicImporter DB = _IS.GetDBImporter();

                await Task.WhenAll(DB.LoadAsync(TP), ScriptConverter.LoadAsync(TP));
            }

            MusicCollectionWPF.Windows.MainWindow window = new MusicCollectionWPF.Windows.MainWindow();
            _AplicationViewModel = new AplicationViewModel(_IS);
            window.Opacity = 0;
            window.Loaded += window_Loaded;
            App.Current.MainWindow = window;

            window.Show();
        }
 public ThreadPropertiesChanger(ThreadProperties itarget)
 {
     _Original = ThreadProperties.FromCurrentThread();
     _Target = itarget;
     _Target.SetCurrentThread();
 }