15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

example application ❘ OC67<br />

This user interface is shown in Figure 49-12.<br />

figure 49-12<br />

Timers are maintained through the DocumentTimer class:<br />

public class DocumentTimer<br />

{<br />

}<br />

public Word.Document Document { get; set; }<br />

public DateTime LastActive { get; set; }<br />

public bool IsActive { get; set; }<br />

public TimeSpan EditTime { get; set; }<br />

code snippet DocumentTimer.cs<br />

This keeps a reference to a Microsoft.Office.Interop.Word.Document interface as well as the total<br />

edit time, whether the timer is active, <strong>and</strong> the time it last became active. The ThisAddIn class maintains a<br />

collection of these objects, associated with document names:<br />

public partial class ThisAddIn<br />

{<br />

private Dictionary documentEditTimes;<br />

code snippet ThisAddIn.cs<br />

Each timer can therefore be located by document reference or document name. This is necessary because<br />

document references allow you to keep track of document name changes (there is no event that you can use<br />

to monitor this), <strong>and</strong> document names allow you to keep track of closed <strong>and</strong> reopened documents.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!