You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [**StorageLibraryChangeTracker**](/uwp/api/Windows.Storage.StorageLibraryChangeTracker) class allows apps to track changes in files and folders as users move them around the system. Using the **StorageLibraryChangeTracker** class, an app can track:
19
+
The [StorageLibraryChangeTracker](/uwp/api/Windows.Storage.StorageLibraryChangeTracker) class allows apps to track changes in files and folders as users move them around the system. Using the StorageLibraryChangeTracker class, an app can track:
20
20
21
21
- File operations including add, delete, modify.
22
22
- Folder operations such as renames and deletes.
23
23
- Files and folders moving on the drive.
24
24
25
-
Use this guide to learn the programing model for working with the change tracker, view some sample code, and understand the different types of file operations that are tracked by **StorageLibraryChangeTracker**.
25
+
Use this guide to learn the programing model for working with the change tracker, view some sample code, and understand the different types of file operations that are tracked by StorageLibraryChangeTracker.
26
26
27
-
**StorageLibraryChangeTracker** works for user libraries, or for any folder on the local machine. This includes secondary drives or removable drives but does not include NAS drives or network drives.
27
+
StorageLibraryChangeTracker works for user libraries, or for any folder on the local machine. This includes secondary drives or removable drives but does not include NAS drives or network drives.
28
28
29
29
## Using the change tracker
30
30
@@ -41,7 +41,7 @@ The next sections walk through each of the steps with some code examples. The co
41
41
42
42
### Enable the change tracker
43
43
44
-
The first thing that the app needs to do is to tell the system that it is interested in change tracking a given library. It does this by calling the [**Enable**](/uwp/api/windows.storage.storagelibrarychangetracker.enable) method on the change tracker for the library of interest.
44
+
The first thing that the app needs to do is to tell the system that it is interested in change tracking a given library. It does this by calling the [Enable](/uwp/api/windows.storage.storagelibrarychangetracker.enable) method on the change tracker for the library of interest.
- Make sure your app has permission to the correct library in the manifest before creating the [**StorageLibrary**](/uwp/api/windows.storage.storagelibrary) object. See [File Access Permissions](./file-access-permissions.md) for more details.
55
-
-[**Enable**](/uwp/api/windows.storage.storagelibrarychangetracker.enable) is thread safe, will not reset your pointer, and can be called as many times as you like (more on this later).
54
+
- Make sure your app has permission to the correct library in the manifest before creating the [StorageLibrary](/uwp/api/windows.storage.storagelibrary) object. See [File Access Permissions](./file-access-permissions.md) for more details.
55
+
-[Enable](/uwp/api/windows.storage.storagelibrarychangetracker.enable) is thread safe, will not reset your pointer, and can be called as many times as you like (more on this later).
56
56
57
57

58
58
59
59
### Wait for changes
60
60
61
-
After the change tracker is initialized, it will begin to record all of the operations that occur within a library, even while the app isn’t running. Apps can register to be activated any time there is a change by registering for the [**StorageLibraryChangedTrigger**](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger) event.
61
+
After the change tracker is initialized, it will begin to record all of the operations that occur within a library, even while the app isn’t running. Apps can register to be activated any time there is a change by registering for the [StorageLibraryChangedTrigger](/uwp/api/Windows.ApplicationModel.Background.StorageLibraryContentChangedTrigger) event.
62
62
63
63

64
64
@@ -78,11 +78,11 @@ The app is then responsible for processing the changes into its own experience o
78
78

79
79
80
80
> [!TIP]
81
-
> The second call to enable is to defend against a race condition if the user adds another folder to the library while your app is reading changes. Without the extra call to **Enable** the code will fail with ecSearchFolderScopeViolation (0x80070490) if the user is changing the folders in their library
81
+
> The second call to enable is to defend against a race condition if the user adds another folder to the library while your app is reading changes. Without the extra call to Enable the code will fail with ecSearchFolderScopeViolation (0x80070490) if the user is changing the folders in their library
82
82
83
83
### Accept the changes
84
84
85
-
After the app is done processing the changes, it should tell the system to never show those changes again by calling the [**AcceptChangesAsync**](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync) method.
85
+
After the app is done processing the changes, it should tell the system to never show those changes again by calling the [AcceptChangesAsync](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync) method.
The app will now only receive new changes when reading the change tracker in the future.
94
94
95
-
- If changes have happened between calling [**ReadBatchAsync**](/uwp/api/windows.storage.storagelibrarychangereader.readbatchasync) and [AcceptChangesAsync](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync), the pointer will be only be advanced to the most recent change the app has seen. Those other changes will still be available the next time it calls **ReadBatchAsync**.
96
-
- Not accepting the changes will cause the system to return the same set of changes the next time the app calls **ReadBatchAsync**.
95
+
- If changes have happened between calling [ReadBatchAsync](/uwp/api/windows.storage.storagelibrarychangereader.readbatchasync) and [AcceptChangesAsync](/uwp/api/windows.storage.storagelibrarychangereader.acceptchangesasync), the pointer will be only be advanced to the most recent change the app has seen. Those other changes will still be available the next time it calls ReadBatchAsync.
96
+
- Not accepting the changes will cause the system to return the same set of changes the next time the app calls ReadBatchAsync.
97
97
98
98
## Important things to remember
99
99
@@ -103,24 +103,24 @@ When using the change tracker, there are a few things that you should keep in mi
103
103
104
104
Although we try to reserve enough space in the change tracker to hold all the operations happening on the system until your app can read them, it is very easy to imagine a scenario where the app doesn’t read the changes before the circular buffer overwrites itself. Especially if the user is restoring data from a backup or syncing a large collection of pictures from their camera phone.
105
105
106
-
In this case, **ReadBatchAsync** will return the error code [**StorageLibraryChangeType.ChangeTrackingLost**](/uwp/api/windows.storage.storagelibrarychangetype). If your app receives this error code, it means a couple things:
106
+
In this case, ReadBatchAsync will return the error code [StorageLibraryChangeType.ChangeTrackingLost](/uwp/api/windows.storage.storagelibrarychangetype). If your app receives this error code, it means a couple things:
107
107
108
108
* The buffer has overwritten itself since the last time you looked at it. The best course of action is to recrawl the library, because any information from the tracker will be incomplete.
109
-
* The change tracker will not return any more changes until you call [**Reset**](/uwp/api/windows.storage.storagelibrarychangetracker.reset). After the app calls reset, the pointer will be moved to the most recent change and tracking will resume normally.
109
+
* The change tracker will not return any more changes until you call [Reset](/uwp/api/windows.storage.storagelibrarychangetracker.reset). After the app calls reset, the pointer will be moved to the most recent change and tracking will resume normally.
110
110
111
111
It should be rare to get these cases, but in scenarios where the user is moving a large number of files around on their disk we don’t want the change tracker to balloon and take up too much storage. This should allow apps to react to massive file system operations while not damaging the customer experience in Windows.
112
112
113
113
### Changes to a StorageLibrary
114
114
115
-
The [**StorageLibrary**](/uwp/api/windows.storage.storagelibrary) class exists as a virtual group of root folders that contain other folders. To reconcile this with a file system change tracker, we made the following choices:
115
+
The [StorageLibrary](/uwp/api/windows.storage.storagelibrary) class exists as a virtual group of root folders that contain other folders. To reconcile this with a file system change tracker, we made the following choices:
116
116
117
-
- Any changes to descendent of the root library folders will be represented in the change tracker. The root library folders can be found using the [**Folders**](/uwp/api/windows.storage.storagelibrary.folders) property.
118
-
- Adding or removing root folders from a **StorageLibrary** (through [**RequestAddFolderAsync**](/uwp/api/windows.storage.storagelibrary.requestaddfolderasync) and [**RequestRemoveFolderAsync**](/uwp/api/windows.storage.storagelibrary.requestremovefolderasync)) will not create an entry in the change tracker. These changes can be tracked through the [**DefinitionChanged**](/uwp/api/windows.storage.storagelibrary.definitionchanged) event or by enumerating the root folders in the library using the [**Folders**](/uwp/api/windows.storage.storagelibrary.folders) property.
117
+
- Any changes to descendent of the root library folders will be represented in the change tracker. The root library folders can be found using the [Folders](/uwp/api/windows.storage.storagelibrary.folders) property.
118
+
- Adding or removing root folders from a StorageLibrary (through [RequestAddFolderAsync](/uwp/api/windows.storage.storagelibrary.requestaddfolderasync) and [RequestRemoveFolderAsync](/uwp/api/windows.storage.storagelibrary.requestremovefolderasync)) will not create an entry in the change tracker. These changes can be tracked through the [DefinitionChanged](/uwp/api/windows.storage.storagelibrary.definitionchanged) event or by enumerating the root folders in the library using the [Folders](/uwp/api/windows.storage.storagelibrary.folders) property.
119
119
- If a folder with content already in it is added to the library, there will not be a change notification or change tracker entries generated. Any subsequent changes to the descendants of that folder will generate notifications and change tracker entries.
120
120
121
121
### Calling the Enable method
122
122
123
-
Apps should call [**Enable**](/uwp/api/windows.storage.storagelibrarychangetracker.enable) as soon as they start tracking the file system and before every enumeration of the changes. This will ensure that all changes will be captured by the change tracker.
123
+
Apps should call [Enable](/uwp/api/windows.storage.storagelibrarychangetracker.enable) as soon as they start tracking the file system and before every enumeration of the changes. This will ensure that all changes will be captured by the change tracker.
0 commit comments