Udostępnij za pośrednictwem


RunningDocumentTable Class

Provides access to the Running Document Table (RDT) that tracks all currently opened documents in Visual Studio.

Namespace:  Microsoft.VisualStudio.Shell
Assembly:  Microsoft.VisualStudio.Shell (in Microsoft.VisualStudio.Shell.dll)

Syntax

'Declaration
Public Class RunningDocumentTable _
    Implements IEnumerable(Of RunningDocumentInfo), IEnumerable
'Usage
Dim instance As RunningDocumentTable
public class RunningDocumentTable : IEnumerable<RunningDocumentInfo>, 
    IEnumerable
public ref class RunningDocumentTable : IEnumerable<RunningDocumentInfo>, 
    IEnumerable
public class RunningDocumentTable implements IEnumerable<RunningDocumentInfo>, IEnumerable

Remarks

The RDT is used to track all documents that are currently opened in Visual Studio, whether they are visible or not. A VSPackage (see VSPackages) can access the RDT by calling the QueryService(Guid, Guid, IntPtr) method on a service provider with the service ID SVsRunningDocumentTable and the GUID of the IVsRunningDocumentTable interface.

The managed package framework's (MPF) RunningDocumentTable class simplifies access to the RDT for VSPackages by hiding the details of the IVsRunningDocumentTable interface behind a collection of useful methods. Note that the RunningDocumentTable class is used only for accessing document information. If you want to track RDT events, you must obtain the IVsRunningDocumentTable interface yourself (through the QueryService(Guid, Guid, IntPtr) method on a service provider) and call the AdviseRunningDocTableEvents method with your own implementation of the IVsRunningDocTableEvents interface (or its derivatives).

The RunningDocumentTable class is primarily used by the MPF classes. For example, the Source class uses the RunningDocumentTable class to obtain the owning project of a document when building the list of error task items for the task windows.

Notes to Implementers:

This class is used to simplify access to finding information about open documents and has no methods that can be overridden. There is nothing to implement.

Notes to Callers:

Instantiate the RunningDocumentTable class to obtain information about an open document. The resulting RunningDocumentTable object is typically cached to enhance performance. Note that this class does not provide complete access to the RDT.

Examples

This example shows how to use the RunningDocumentTable object from a language service to obtain the owning project of a file currently open in the editor.

using Microsoft.VisualStudio.Package;

namespace MyLanguagePackage
{
    public class MyLanguageService : LanguageService
    {
        IServiceProvider serviceProvider;

        public IVsHierarchy GetOwningProject(Source src)
        {
            RunningDocumentTable rdt = new RunningDocumentTable(this.serviceProvider);
            string filename = src.GetFilePath();
            return rdt.GetHierarchyItem(filename);
        }
    }
}

Inheritance Hierarchy

System.Object
  Microsoft.VisualStudio.Shell.RunningDocumentTable

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

RunningDocumentTable Members

Microsoft.VisualStudio.Shell Namespace