File tree 2 files changed +10
-8
lines changed 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ public partial class MainWindow : Window {
25
25
26
26
Timer updateTimer ;
27
27
28
- volatile bool updatesLocker ;
28
+ bool updatesLocker ;
29
29
30
30
Random random ;
31
31
@@ -36,12 +36,12 @@ public MainWindow() {
36
36
updateTimer = new Timer ( UpdateRows , null , 0 , 1 ) ;
37
37
}
38
38
39
- private void OnRowEditStarted ( object sender , RowEditStartedEventArgs e ) => updatesLocker = true ;
39
+ private void OnRowEditStarted ( object sender , RowEditStartedEventArgs e ) => Volatile . Write ( ref updatesLocker , true ) ;
40
40
41
- private void OnRowEditFinished ( object sender , RowEditFinishedEventArgs e ) => updatesLocker = false ;
41
+ private void OnRowEditFinished ( object sender , RowEditFinishedEventArgs e ) => Volatile . Write ( ref updatesLocker , false ) ;
42
42
43
43
void UpdateRows ( object parameter ) {
44
- if ( ! updatesLocker ) {
44
+ if ( ! Volatile . Read ( ref updatesLocker ) ) {
45
45
var row = data [ random . Next ( 0 , data . Count ) ] ;
46
46
if ( row . ShouldUpdate ) {
47
47
row . Value = random . Next ( 1 , 100 ) ;
Original file line number Diff line number Diff line change 3
3
using DevExpress . Mvvm . Xpf ;
4
4
using System ;
5
5
using System . Collections . ObjectModel ;
6
+ using System . ComponentModel ;
6
7
using System . Linq ;
7
8
using System . Threading ;
9
+ using System . Windows . Threading ;
8
10
9
11
namespace LockOnRowEdit_MVVM {
10
12
public class DataItem : BindableBase {
@@ -27,7 +29,7 @@ public class MainViewModel : ViewModelBase {
27
29
28
30
Timer updateTimer ;
29
31
30
- volatile bool updatesLocker ;
32
+ bool updatesLocker ;
31
33
32
34
public MainViewModel ( ) {
33
35
random = new Random ( ) ;
@@ -36,13 +38,13 @@ public MainViewModel() {
36
38
}
37
39
38
40
[ Command ]
39
- public void LockUpdates ( RowEditStartedArgs args ) => updatesLocker = true ;
41
+ public void LockUpdates ( RowEditStartedArgs args ) => Volatile . Write ( ref updatesLocker , true ) ;
40
42
41
43
[ Command ]
42
- public void UnlockUpdates ( RowEditFinishedArgs args ) => updatesLocker = false ;
44
+ public void UnlockUpdates ( RowEditFinishedArgs args ) => Volatile . Write ( ref updatesLocker , false ) ;
43
45
44
46
void UpdateRows ( object parameter ) {
45
- if ( ! updatesLocker ) {
47
+ if ( ! Volatile . Read ( ref updatesLocker ) ) {
46
48
var row = Data [ random . Next ( 0 , Data . Count ) ] ;
47
49
if ( row . ShouldUpdate ) {
48
50
row . Value = random . Next ( 1 , 100 ) ;
You can’t perform that action at this time.
0 commit comments