-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathViewModel.vb
77 lines (60 loc) · 2.14 KB
/
ViewModel.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Imports DevExpress.Mvvm
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Threading
Namespace DXGridThreads
Public Class DataItem
Inherits BindableBase
Public Property Name As String
Get
Return GetValue(Of String)()
End Get
Set(ByVal value As String)
SetValue(value)
End Set
End Property
Public Property Value As Integer
Get
Return GetValue(Of Integer)()
End Get
Set(ByVal value As Integer)
SetValue(value)
End Set
End Property
End Class
Public Class ViewModel
Inherits ViewModelBase
Public Property Source As ObservableCollection(Of DataItem)
Public ReadOnly Property GridUpdateService As IGridUpdateService
Get
Return GetService(Of IGridUpdateService)()
End Get
End Property
Public Sub New()
timer = New Timer(AddressOf TimerCallback, Nothing, 1000, 1000)
Source = New ObservableCollection(Of DataItem)(GetData())
End Sub
Private Shared SyncRoot As Object = New Object()
Private timer As Timer
Private random As Random = New Random()
Private Sub TimerCallback(ByVal state As Object)
SyncLock SyncRoot
If GridUpdateService IsNot Nothing Then
GridUpdateService.BeginUpdate()
For Each item As DataItem In Source
item.Value = random.Next(100)
Next
GridUpdateService.EndUpdate()
End If
End SyncLock
End Sub
Private Shared Iterator Function GetData() As IEnumerable(Of DataItem)
Dim i = 0
While i < 100
Yield New DataItem() With {.Name = $"Name {i}", .Value = i}
Interlocked.Increment(i)
End While
End Function
End Class
End Namespace