Beispiel #1
0
 public IAsyncResult BeginInvoke(Delegate method, object[] args) {
     MainThreadTask task = new MainThreadTask(this.mainThread, method, args);
     Queue(task);
     return task; // wait for onidle.
 }
Beispiel #2
0
 /// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.Invoke"]/*' />
 public object Invoke(Delegate method, object[] args) {
     MainThreadTask task = new MainThreadTask(this.mainThread, method, args);
     if (!task.CompletedSynchronously) {
         Queue(task);
         task.AsyncWaitHandle.WaitOne(); // wait for onidle loop.
     }
     object result = task.AsyncState;
     return result;
 }
Beispiel #3
0
 void ClearTask() {
     lock (this) {
         this.task = this.tail = null;
     }
 }
Beispiel #4
0
 internal void RunTasks() {
     MainThreadTask task = Dequeue();
     while (task != null) {
         task.Run();
         task = Dequeue();
     }
 }
Beispiel #5
0
 MainThreadTask Dequeue() {
     lock (this) {
         MainThreadTask result = null;
         if (this.task != null) {
             result = this.task;
             this.task = result.Next;
             if (this.task == null) {
                 this.tail = null;
             }
         }
         return result;
     }
 }
Beispiel #6
0
 void Queue(MainThreadTask task) {
     lock (this) {
         if (this.tail != null) { // might actually be running!
             this.tail.Next = task; // quietly append the new task
         } else {
             this.task = task;
             // Ping our viewfilter to fire up RunTasks rather than waiting for OnIdle.
             IVsUIShell shell = (IVsUIShell)this.GetService(typeof(IVsUIShell));
             if (shell != null) {
                 object pvaIn = null;
                 Guid lang = typeof(LanguageServiceCommands).GUID;
                 shell.PostExecCommand(ref lang, (uint)LanguageServiceCommands.RunTasks, 0, ref pvaIn);
             }
         }
         this.tail = task;
     }
 }
Beispiel #7
0
        /// <include file='doc\LanguageService.uex' path='docs/doc[@for="LanguageService.Done"]/*' />
        /// <summary>
        /// Cleanup the sources, uiShell, shell, preferences and imageList objects
        /// and unregister this language service with VS.
        /// </summary>
        public virtual void Dispose() {
            OnActiveViewChanged(null);
            this.disposed = true;
            this.StopThread();
            this.lastActiveView = null;
            if (this.sources != null) {
                foreach (Source s in this.sources) {
                    s.Dispose();
                }
                this.sources.Clear();
                this.sources = null;
            }
            if (this.colorizers != null) {
                foreach (Colorizer c in this.colorizers) {
                    c.Dispose();
                }
                this.colorizers.Clear();
                this.colorizers = null;
            }

            if (this.codeWindowManagers != null) {
                foreach (CodeWindowManager m in this.codeWindowManagers) {
                    m.Close();
                }
                this.codeWindowManagers.Clear();
                this.codeWindowManagers = null;
            }

            if (this.preferences != null) {
                this.preferences.Dispose();
                this.preferences = null;
            }
            if (this.debugger != null && this.cookie != 0) {
                NativeMethods.ThrowOnFailure(this.debugger.UnadviseDebuggerEvents(this.cookie));
                this.cookie = 0;
                this.debugger = null;
            }
            if (this.task != null)
                this.task.Dispose();
            this.task = null;
            this.site = null;
        }
 void Queue(MainThreadTask task)
 {
     lock (this.control) { // do not lock "this" because it causes deadlocks.
         if (this.tail != null) { // might actually be running!
             this.tail.Next = task; // quietly append the new task
         } else {
             this.task = task;
             if (this.control != null) {
                 // Ping RunTasks right away rather than waiting for OnIdle.
                 this.control.PostRunTasks();
             }
         }
         this.tail = task;
     }
 }
 void ClearTask()
 {
     lock (this.control) {
         this.task = this.tail = null;
     }
 }