Пример #1
0
        private void DoLoadSF(object data)
        {
            LoadSFData loadSFData = (LoadSFData)data;

            while (!_isSMLoaded)
            {
                Thread.Sleep(50);
            }

            Main.Trace.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 0, "DoLoadSF(object data) 0, thread " + Thread.CurrentThread.Name + Thread.CurrentThread.GetHashCode());
            Main.Trace.Flush();

            ScriptFile sf = null;

            try
            {
                sf = scriptManager.GetSFFromFullPath(loadSFData.FullPath);
                if (sf != null && (sf.SC == null || sf.ReadingState < ReadingState.CheckCode || sf.IsSourceFileUpdated()))
                {
                    sf.ReadSC();

                    if (sf.SC != null)
                    {
                        sf.CheckSC();
                    }
                }
            }
            catch (ThreadAbortException)
            { }
            catch (Exception e)
            {
                Main.NotifyError(e);
            }

            Main.Trace.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 0, "DoLoadSF(object data) 1, thread " + Thread.CurrentThread.Name + Thread.CurrentThread.GetHashCode());
            Main.Trace.Flush();

            currentSFFiles.Remove(loadSFData.FullPath.ToLowerInvariant());

            if (sf != null)
            {
                _currentUpdatedFiles.Add(sf);
            }

            //if (lastSFThread == Thread.CurrentThread) // fire event only if this is last SF reading...
            _dispatcher.Invoke(loadSFData.Callback, loadSFData.FullPath, sf);
            //loadSFData.Callback.Invoke(loadSFData.FullPath, sf); // volá funkciu v tomto threade, volanie treba presunúť do hlavného threadu!
        }
Пример #2
0
        public void LoadSF(string fullPath, Action <string, ScriptFile> callback)
        {
            if (currentSFFiles.Contains(fullPath.ToLowerInvariant()))
            {
                return;
            }

            currentSFFiles.Add(fullPath.ToLowerInvariant());

            LoadSFData data = new LoadSFData(fullPath, callback);
            Thread     t    = new Thread(DoLoadSF);

            t.IsBackground = true;
            t.Name         = "Loading SF '" + fullPath + "' thread";
            t.Start(data);

            lastSFThread = t;

            Main.Trace.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 0, "LoadSF, thread " + Thread.CurrentThread.Name + Thread.CurrentThread.GetHashCode());
            Main.Trace.Flush();
        }