Skip to content

Commit

Permalink
Merge branch 'master' into update-skia
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkatz6 authored Aug 13, 2022
2 parents 6d5b59c + 63351a0 commit 643a035
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 55 deletions.
45 changes: 16 additions & 29 deletions src/Android/Avalonia.Android/AndroidThreadingInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,33 @@ public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Ac
{
if (interval.TotalMilliseconds < 10)
interval = TimeSpan.FromMilliseconds(10);
object l = new object();

var stopped = false;
Timer timer = null;
var scheduled = false;
timer = new Timer(_ =>
{
lock (l)
if (stopped)
return;

EnsureInvokeOnMainThread(() =>
{
if (stopped)
try
{
timer.Dispose();
return;
tick();
}
if (scheduled)
return;
scheduled = true;
EnsureInvokeOnMainThread(() =>
finally
{
try
{
tick();
}
finally
{
lock (l)
{
scheduled = false;
}
}
});
}
}, null, TimeSpan.Zero, interval);
if (!stopped)
timer.Change(interval, Timeout.InfiniteTimeSpan);
}
});
},
null, interval, Timeout.InfiniteTimeSpan);

return Disposable.Create(() =>
{
lock (l)
{
stopped = true;
timer.Dispose();
}
stopped = true;
timer.Dispose();
});
}

Expand Down
32 changes: 32 additions & 0 deletions src/Avalonia.Controls.DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,38 @@ protected override Size MeasureOverride(Size availableSize)

return desiredSize;
}

/// <inheritdoc/>
protected override void OnDataContextBeginUpdate()
{
base.OnDataContextBeginUpdate();
foreach (DataGridRow row in GetAllRows())
{
foreach (DataGridCell cell in row.Cells)
{
if (cell.Content is StyledElement)
{
DataContextProperty.Notifying?.Invoke((IAvaloniaObject)cell.Content, true);
}
}
}
}

/// <inheritdoc/>
protected override void OnDataContextEndUpdate()
{
base.OnDataContextEndUpdate();
foreach (DataGridRow row in GetAllRows())
{
foreach (DataGridCell cell in row.Cells)
{
if (cell.Content is StyledElement)
{
DataContextProperty.Notifying?.Invoke((IAvaloniaObject)cell.Content, false);
}
}
}
}

/// <summary>
/// Raises the BeginningEdit event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public TimerImpl(DispatcherPriority priority, TimeSpan interval, Action tick)
_priority = priority;
_interval = interval;
_tick = tick;
_timer = new Timer(OnTimer, null, interval, TimeSpan.FromMilliseconds(-1));
_timer = new Timer(OnTimer, null, interval, Timeout.InfiniteTimeSpan);
_handle = GCHandle.Alloc(_timer);
}

Expand All @@ -57,7 +57,7 @@ private void OnTimer(object? state)
if (_timer == null)
return;
_tick();
_timer?.Change(_interval, TimeSpan.FromMilliseconds(-1));
_timer?.Change(_interval, Timeout.InfiniteTimeSpan);
});
}

Expand Down
48 changes: 24 additions & 24 deletions src/Avalonia.Headless/HeadlessPlatformThreadingInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,35 @@ public void RunLoop(CancellationToken cancellationToken)

public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick)
{
var cancelled = false;
var enqueued = false;
var l = new object();
var timer = new Timer(_ =>
if (interval.TotalMilliseconds < 10)
interval = TimeSpan.FromMilliseconds(10);

var stopped = false;
Timer timer = null;
timer = new Timer(_ =>
{
lock (l)
if (stopped)
return;

Dispatcher.UIThread.Post(() =>
{
if (cancelled || enqueued)
return;
enqueued = true;
Dispatcher.UIThread.Post(() =>
try
{
lock (l)
{
enqueued = false;
if (cancelled)
return;
tick();
}
}, priority);
}
}, null, interval, interval);
tick();
}
finally
{
if (!stopped)
timer.Change(interval, Timeout.InfiniteTimeSpan);
}
});
},
null, interval, Timeout.InfiniteTimeSpan);

return Disposable.Create(() =>
{
lock (l)
{
timer.Dispose();
cancelled = true;
}
stopped = true;
timer.Dispose();
});
}

Expand Down

0 comments on commit 643a035

Please sign in to comment.