Skip to content

Improve performance of watcher #6012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Files/Files.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@
<Compile Include="Helpers\SidebarHelpers.cs" />
<Compile Include="Helpers\XamlHelpers\DependencyObjectHelpers.cs" />
<Compile Include="Helpers\XamlHelpers\SystemTypeToXaml.cs" />
<Compile Include="Helpers\AsyncManualResetEvent.cs" />
<Compile Include="IBaseLayout.cs" />
<Compile Include="Interacts\BaseLayoutCommandImplementationModel.cs" />
<Compile Include="Interacts\BaseLayoutCommandsViewModel.cs" />
Expand Down
12 changes: 11 additions & 1 deletion Files/Filesystem/ListedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using Windows.Storage;
using Windows.UI.Xaml.Media.Imaging;

Expand All @@ -22,7 +23,16 @@ public class ListedItem : ObservableObject, IGroupableItem
{
public bool IsHiddenItem { get; set; } = false;
public StorageItemTypes PrimaryItemAttribute { get; set; }
public bool ItemPropertiesInitialized { get; set; } = false;

private volatile int itemPropertiesInitialized = 0;
public bool ItemPropertiesInitialized
{
get => itemPropertiesInitialized == 1;
set
{
Interlocked.Exchange(ref itemPropertiesInitialized, value ? 1 : 0);
}
}

public string ItemTooltipText
{
Expand Down
61 changes: 61 additions & 0 deletions Files/Helpers/AsyncManualResetEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Files.Helpers
{
public class AsyncManualResetEvent
{
private volatile TaskCompletionSource<bool> m_tcs = new TaskCompletionSource<bool>();

public async Task WaitAsync(CancellationToken cancellationToken = default)
{
var tcs = m_tcs;
var cancelTcs = new TaskCompletionSource<bool>();

cancellationToken.Register(
s => ((TaskCompletionSource<bool>)s).TrySetCanceled(), cancelTcs);

await await Task.WhenAny(tcs.Task, cancelTcs.Task);
}

private async Task<bool> Delay(int milliseconds)
{
await Task.Delay(milliseconds);
return false;
}

public async Task<bool> WaitAsync(int milliseconds, CancellationToken cancellationToken = default)
{
var tcs = m_tcs;
var cancelTcs = new TaskCompletionSource<bool>();

cancellationToken.Register(
s => ((TaskCompletionSource<bool>)s).TrySetCanceled(), cancelTcs);

return await await Task.WhenAny(tcs.Task, cancelTcs.Task, Delay(milliseconds));
}

public void Set()
{
var tcs = m_tcs;
Task.Factory.StartNew(s => ((TaskCompletionSource<bool>)s).TrySetResult(true),
tcs, CancellationToken.None, TaskCreationOptions.PreferFairness, TaskScheduler.Default);
tcs.Task.Wait();
}

public void Reset()
{
while (true)
{
var tcs = m_tcs;
if (!tcs.Task.IsCompleted ||
Interlocked.CompareExchange(ref m_tcs, new TaskCompletionSource<bool>(), tcs) == tcs)
return;
}
}
}
}
Loading