question

65010773 avatar image
65010773 asked ·

list of t has 0 element after exit file

Hi

I read a textfile and make some processing and get data in listtime when i check the listtime in the scope of the sub where i do processing ,listtime has N element but after exit the sub it has no element ?

  ![8220-im1.png][1]


8325-im2.png


here the watch of the debugger
8392-watch1.png
8441-watch2.png


[1]: /answers/storage/attachments/8220-im1.png


Thanks

windows-uwp
im1.png (7.1 KiB)
im2.png (115.0 KiB)
watch1.png (68.0 KiB)
watch2.png (41.0 KiB)
2 comments
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, if you use await the execution of method ends before all instructions are executed. Use NotifiPropertyChanged to inform about the end of method.

0 Votes 0 · ·

Have you solved your issue? Does @PeterFleischer-3316 's answer work on your side?

0 Votes 0 · ·
65010773 avatar image
65010773 answered ·

Hi

I don't succeed to achieve my goal

8445-im1.png



im1.png (47.0 KiB)
1 comment Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, my code demonstrates that task run in separat thread and you cannot get the expected result. You can start readFile and process the end of the asynchronous work in a separate event routine.

0 Votes 0 · ·
PeterFleischer-3316 avatar image
PeterFleischer-3316 answered ·

Hi, if you use await the execution of method ends before all instructions are executed. Try following code and check debug result in "Immediate Window". Use NotifyPropertyChanged to inform about the end of method.

8404-x.png

Another approach is to use LoadList as function:

8370-x2.png



x.png (38.4 KiB)
x2.png (49.0 KiB)
Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

yanxiaodi avatar image
yanxiaodi answered ·

You need to use await for your async method. eg. await read-file()

You also need to change MainPage_Loading() to an async method. If you don't use await for read-file(), you will hit the end of MainPage_Loading() before read-file() returns its result.


Sorry because I cannot post "readfile" here so please use your method name to replace it.

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.