Skip to content

Commit eeec372

Browse files
Merge pull request #18 from AndreasReitberger/17-add-setbusy-methods-to-viewmodelbase
Added `IsBusy` method to `ViewModelBase`
2 parents 962109e + adaac39 commit eeec372

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<Project>
33
<PropertyGroup>
4-
<Version>1.0.1</Version>
4+
<Version>1.0.2</Version>
55
<PackageIcon>ar_128.png</PackageIcon>
66
<NeutralLanguage>en</NeutralLanguage>
77
<PackageProjectUrl>https://github.com/AndreasReitberger/SharedXFormCoreLibrary</PackageProjectUrl>

src/SharedXFormCoreLibrary/Models/ViewModelBase.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using AndreasReitberger.Shared.XForm.Core.Interfaces;
22
using CommunityToolkit.Mvvm.ComponentModel;
3+
using System.Threading.Tasks;
34

45
namespace AndreasReitberger.Shared.XForm.Core
56
{
@@ -80,6 +81,32 @@ public ViewModelBase(IDispatcher dispatcher, IServiceProvider provider)
8081
}
8182
#endregion
8283

84+
#region Methods
85+
public void SetBusy(bool isBusy, IDispatcher? dispatcher)
86+
{
87+
// Only dispatch if needed
88+
if (dispatcher is not null && dispatcher?.IsInvokeRequired is true)
89+
{
90+
dispatcher.BeginInvokeOnMainThread(() =>
91+
{
92+
if (isBusy)
93+
IsBusyCounter++;
94+
else
95+
IsBusyCounter--;
96+
});
97+
}
98+
// Update on the MainThread
99+
else
100+
{
101+
if (isBusy)
102+
IsBusyCounter++;
103+
else
104+
IsBusyCounter--;
105+
}
106+
}
107+
108+
#endregion
109+
83110
#region Dispose
84111
/*
85112
public void Dispose()

0 commit comments

Comments
 (0)