vb.net - "Invalid cross-thread access" when changing a WP8 textBlock -
i'm coming vb 6 , semi-new vb.net. i'm writing windows phone 8 application. there's grid in have several textblocks want dynamically display data file stream (that contains scanned data).
when wp8 page opens, automatically loads data textblocks. works. before load data file, want "reset" textblocks , hide them. wanted use procedure following every textblock:
tbl1.text = "" tbl1.visibility = system.windows.visibility.collapsed
this works 1 time: when page loads. procedure not produce error.
now when call method again later, when want refresh data shown on page, following error on first line of code shown above:
an exception of type 'system.unauthorizedaccessexception' occurred in system.windows.ni.dll not handled in user code additional information: invalid cross-thread access.
i'm bit lost now. in vb6 able whatever wanted ui elements. presume i'm making kind of newbie mistake here?
i read somewhere dispatcher thing. seems overly complicated change value in textblock me. there no simple way?
the solution indeed use dispatcher.begininvoke
method.
dispatcher.begininvoke(() => { tbl1.text = "" tbl1.visibility = system.windows.visibility.collapsed });
the reason why need because try access object depends on ui thread non-ui thread.
Comments
Post a Comment