3838
3939using Opc . Ua . Client ;
4040using Opc . Ua . Client . Controls ;
41+ using System . Threading . Tasks ;
4142
4243namespace Opc . Ua . Sample . Controls
4344{
@@ -46,8 +47,8 @@ public partial class DataValueListCtrl : Opc.Ua.Client.Controls.BaseListCtrl
4647 #region Constructors
4748 public DataValueListCtrl ( )
4849 {
49- InitializeComponent ( ) ;
50- SetColumns ( m_ColumnNames ) ;
50+ InitializeComponent ( ) ;
51+ SetColumns ( m_ColumnNames ) ;
5152 }
5253 #endregion
5354
@@ -59,24 +60,24 @@ public DataValueListCtrl()
5960 /// The columns to display in the control.
6061 /// </summary>
6162 private readonly object [ ] [ ] m_ColumnNames = new object [ ] [ ]
62- {
63- new object [ ] { "Node" , HorizontalAlignment . Left , null } ,
64- new object [ ] { "Attribute" , HorizontalAlignment . Left , "Value" , } ,
65- new object [ ] { "Value" , HorizontalAlignment . Left , "" , 200 } ,
66- new object [ ] { "Status" , HorizontalAlignment . Left , "" } ,
67- new object [ ] { "Source Time" , HorizontalAlignment . Left , "" } ,
68- new object [ ] { "Server Time" , HorizontalAlignment . Left , "" } ,
69- } ;
70- #endregion
63+ {
64+ new object [ ] { "Node" , HorizontalAlignment . Left , null } ,
65+ new object [ ] { "Attribute" , HorizontalAlignment . Left , "Value" , } ,
66+ new object [ ] { "Value" , HorizontalAlignment . Left , "" , 200 } ,
67+ new object [ ] { "Status" , HorizontalAlignment . Left , "" } ,
68+ new object [ ] { "Source Time" , HorizontalAlignment . Left , "" } ,
69+ new object [ ] { "Server Time" , HorizontalAlignment . Left , "" } ,
70+ } ;
71+ #endregion
7172
7273 #region Public Interface
7374 /// <summary>
7475 /// The control used to display the details of a value.
7576 /// </summary>
7677 public DataListCtrl DataListCtrl
7778 {
78- get { return m_DataListCtrl ; }
79- set { m_DataListCtrl = value ; }
79+ get { return m_DataListCtrl ; }
80+ set { m_DataListCtrl = value ; }
8081 }
8182
8283 /// <summary>
@@ -91,25 +92,25 @@ public void Clear()
9192 /// <summary>
9293 /// Sets the nodes in the control.
9394 /// </summary>
94- public void Initialize (
95- Session session ,
96- ReadValueIdCollection valueIds ,
97- DataValueCollection values ,
98- List < ServiceResult > results )
95+ public async Task InitializeAsync (
96+ Session session ,
97+ ReadValueIdCollection valueIds ,
98+ DataValueCollection values ,
99+ List < ServiceResult > results )
99100 {
100101 if ( session == null ) throw new ArgumentNullException ( "session" ) ;
101-
102+
102103 Clear ( ) ;
103-
104- m_session = session ;
104+
105+ m_session = session ;
105106
106107 if ( valueIds != null )
107108 {
108109 for ( int ii = 0 ; ii < valueIds . Count ; ii ++ )
109110 {
110111 ValueItem item = new ValueItem ( ) ;
111112
112- item . Node = m_session . NodeCache . Find ( valueIds [ ii ] . NodeId ) as Node ;
113+ item . Node = await m_session . NodeCache . FindAsync ( valueIds [ ii ] . NodeId ) as Node ;
113114 item . AttributeId = valueIds [ ii ] . AttributeId ;
114115
115116 if ( values != null && ii < values . Count )
@@ -132,26 +133,26 @@ public void Initialize(
132133 /// <summary>
133134 /// Sets the nodes in the control.
134135 /// </summary>
135- public void Initialize (
136- Session session ,
137- WriteValueCollection values ,
138- List < ServiceResult > results )
136+ public async Task InitializeAsync (
137+ Session session ,
138+ WriteValueCollection values ,
139+ List < ServiceResult > results )
139140 {
140141 if ( session == null ) throw new ArgumentNullException ( "session" ) ;
141-
142+
142143 Clear ( ) ;
143-
144+
144145 m_session = session ;
145-
146+
146147 if ( values != null )
147148 {
148149 for ( int ii = 0 ; ii < values . Count ; ii ++ )
149150 {
150151 ValueItem item = new ValueItem ( ) ;
151152
152- item . Node = m_session . NodeCache . Find ( values [ ii ] . NodeId ) as Node ;
153+ item . Node = await m_session . NodeCache . FindAsync ( values [ ii ] . NodeId ) as Node ;
153154 item . AttributeId = values [ ii ] . AttributeId ;
154- item . Value = values [ ii ] . Value ;
155+ item . Value = values [ ii ] . Value ;
155156
156157 if ( results != null && ii < results . Count )
157158 {
@@ -164,35 +165,35 @@ public void Initialize(
164165
165166 AdjustColumns ( ) ;
166167 }
167- #endregion
168-
168+ #endregion
169+
169170 #region NodeField Class
170171 /// <summary>
171172 /// A field associated with a node.
172173 /// </summary>
173174 private class ValueItem
174- {
175+ {
175176 public Node Node ;
176177 public uint AttributeId ;
177178 public DataValue Value ;
178179 public ServiceResult Result ;
179180 }
180- #endregion
181+ #endregion
181182
182183 #region Private Methods
183- #endregion
184-
184+ #endregion
185+
185186 #region Overridden Methods
186187 /// <see cref="BaseListCtrl.UpdateItem" />
187188 protected override void UpdateItem ( ListViewItem listItem , object item )
188189 {
189- ValueItem dataValue = item as ValueItem ;
190+ ValueItem dataValue = item as ValueItem ;
190191
191- if ( dataValue == null )
192- {
193- base . UpdateItem ( listItem , item ) ;
194- return ;
195- }
192+ if ( dataValue == null )
193+ {
194+ base . UpdateItem ( listItem , item ) ;
195+ return ;
196+ }
196197
197198 listItem . SubItems [ 0 ] . Text = String . Format ( "{0}" , dataValue . Node ) ;
198199 listItem . SubItems [ 1 ] . Text = Attributes . GetBrowseName ( dataValue . AttributeId ) ;
@@ -218,12 +219,12 @@ protected override void UpdateItem(ListViewItem listItem, object item)
218219
219220 if ( dataValue . Result != null )
220221 {
221- listItem . SubItems [ 3 ] . Text = String . Format ( "{0}" , dataValue . Result ) ;
222+ listItem . SubItems [ 3 ] . Text = String . Format ( "{0}" , dataValue . Result ) ;
222223 }
223224
224- listItem . Tag = item ;
225+ listItem . Tag = item ;
225226 }
226-
227+
227228 /// <see cref="BaseListCtrl.SelectItems" />
228229 protected override void SelectItems ( )
229230 {
0 commit comments