Skip to content

Commit 7420dd2

Browse files
Merge pull request #11 from ShawnLaMountain/main
INotifyPropertyChangedExtension supports NotifyAndWait or FireAndForget
2 parents 88c80c8 + 678cecb commit 7420dd2

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/ThunderDesign.Net-PCL.Threading/Extentions/INotifyPropertyChangedExtension.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,25 @@ public static class INotifyPropertyChangedExtension
1010
public static void NotifyPropertyChanged(
1111
this INotifyPropertyChanged sender,
1212
PropertyChangedEventHandler handler,
13-
[CallerMemberName] string propertyName = "")
13+
[CallerMemberName] string propertyName = "",
14+
bool notifyAndWait = false)
1415
{
15-
sender.NotifyPropertyChanged(handler, new PropertyChangedEventArgs(propertyName));
16+
sender.NotifyPropertyChanged(handler, new PropertyChangedEventArgs(propertyName), notifyAndWait);
1617
}
1718

1819
public static void NotifyPropertyChanged(
1920
this INotifyPropertyChanged sender,
2021
PropertyChangedEventHandler handler,
21-
PropertyChangedEventArgs args)
22+
PropertyChangedEventArgs args,
23+
bool notifyAndWait = false)
2224
{
2325
// Calling 'Invoke' can cause DeadLocks and 'BeginInvoke' can cause System.PlatformNotSupportedException errors so calling Invoke from within a Thread
2426
//handler?.Invoke(sender, args);
2527
//handler?.BeginInvoke(sender, args, ar => { }, null);
26-
ThreadHelper.RunAndForget(() => handler?.Invoke(sender, args));
28+
if (notifyAndWait)
29+
handler?.Invoke(sender, args);
30+
else
31+
ThreadHelper.RunAndForget(() => handler?.Invoke(sender, args));
2732
}
2833

2934
public static bool SetProperty<T>(

0 commit comments

Comments
 (0)