Tech Off Post

Single Post Permalink

View Thread: I was told today to not worry cross-thread execution when...
  • User profile image
    Sven Groot

    Minh said:
    wkempf said:
    Here's what I'm able to gather...

    From this ScottGu post he had this code sample...

    Later in the callback method, he assigned the data to the grid.

    So either Scott is blatantly ignoring UI threading rules, or they work some sort of automatic UI thread synchronization, at least on callbacks.

    I'm not sure if this is the case in Silverlight, but in regular .Net the Async pattern (unlike the Begin/EndInvoke pattern) makes sure that the Completed event is raised on the UI thread. So using UI methods from the DownloadStoriesCompleted event handler is safe since it's already on the correct thread.

    This uses the AsyncOperation class introduced in .Net 2.0, it's also what BackgroundWorker uses internally.