{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/comments/166076073","pull_request_review_id":94102874,"id":166076073,"diff_hunk":"@@ -328,50 +363,63 @@ public void OnResume(Action onBackPressed)\n         /// associated with the provided root view will be started\n         /// asynchronously. This view will then be tracked by this manager and\n         /// in case of React instance restart, it will be re-attached.\n+        /// WARNING! Has to be called by the thread associated with the view.\n         /// </summary>\n         /// <param name=\"rootView\">The root view.</param>\n-        public void AttachMeasuredRootView(ReactRootView rootView)\n+        public async Task AttachMeasuredRootViewAsync(ReactRootView rootView)\n         {\n             if (rootView == null)\n                 throw new ArgumentNullException(nameof(rootView));\n \n-            DispatcherHelpers.AssertOnDispatcher();\n+            DispatcherHelpers.AssertOnDispatcher(rootView);\n             rootView.Children.Clear();\n             rootView.ClearData();\n-            _attachedRootViews.Add(rootView);\n \n-            // If the React context is being created in the background, the\n-            // JavaScript application will be started automatically when\n-            // creation completes, as root view is part of the attached root\n-            // view list.\n-            var currentReactContext = _currentReactContext;\n-            if (_contextInitializationTask == null && currentReactContext != null)\n+            await DispatcherHelpers.CallOnDispatcher(() =>\n             {","path":"ReactWindows/ReactNative.Shared/ReactInstanceManager.cs","position":250,"original_position":250,"commit_id":"703fa54a4c16b399cefbf2adc09eabde6ed094b6","original_commit_id":"703fa54a4c16b399cefbf2adc09eabde6ed094b6","user":{"login":"reseul","id":11672053,"avatar_url":"https://avatars3.githubusercontent.com/u/11672053?v=4","gravatar_id":"","url":"https://api.github.com/users/reseul","html_url":"https://github.com/reseul","followers_url":"https://api.github.com/users/reseul/followers","following_url":"https://api.github.com/users/reseul/following{/other_user}","gists_url":"https://api.github.com/users/reseul/gists{/gist_id}","starred_url":"https://api.github.com/users/reseul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reseul/subscriptions","organizations_url":"https://api.github.com/users/reseul/orgs","repos_url":"https://api.github.com/users/reseul/repos","events_url":"https://api.github.com/users/reseul/events{/privacy}","received_events_url":"https://api.github.com/users/reseul/received_events","type":"User","site_admin":false},"body":"Yeah, there are some ridiculous rules/behaviors.\r\n1. You can access both <view>.Dispatcher and <view>.CoreWindow.Dispatcher from a worker thread.\r\n2. You can access <view>.Dispatcher but you CAN'T <view>.CoreWindow from a different Dispatcher thread... You get that ASTA related exception with the deadlock scare in that case (I guess because the current Dispatcher is in a COM apartment already. I don't know the details of how .NET uses COM apartments, I know cross apartment calls are automatically marshalled through COM provided message loops so no deadlock should happen, maybe just reentrancy, but I digress).\r\nI avoid using .CoreWindow for other reasons, like cases where that windo is not set yet, etc.\r\n\r\nOther peculiarities:\r\n- CoreApplication.MainView raises exception during Application constructor, yet CoreApplication.GetCurrentView() returns what seems to be the right thing (a view with IsMain == true)\r\n- In some early scenarios that are about app being instantiated/activated from a different thread CoreApplication.MainView.Dispatcher fails with Exception(HRESULT_FROM(ELEMENT_NOT_FOUND)) :)\r\n- The lack of SynchronizationContext in that case after init is done (we have that one bug/workaround for this).\r\n\r\n\r\n---\r\nIn reply to: [165967906](https://github.com/Microsoft/react-native-windows/pull/1615#discussion_r165967906) [](ancestors = 165967906)","created_at":"2018-02-05T18:58:32Z","updated_at":"2018-02-05T18:58:32Z","html_url":"https://github.com/Microsoft/react-native-windows/pull/1615#discussion_r166076073","pull_request_url":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/comments/166076073"},"html":{"href":"https://github.com/Microsoft/react-native-windows/pull/1615#discussion_r166076073"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615"}},"in_reply_to_id":165967906},"pull_request":{"url":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615","id":166945508,"html_url":"https://github.com/Microsoft/react-native-windows/pull/1615","diff_url":"https://github.com/Microsoft/react-native-windows/pull/1615.diff","patch_url":"https://github.com/Microsoft/react-native-windows/pull/1615.patch","issue_url":"https://api.github.com/repos/Microsoft/react-native-windows/issues/1615","number":1615,"state":"open","locked":false,"title":"Multi window (UWP CoreApplicationView) support","user":{"login":"reseul","id":11672053,"avatar_url":"https://avatars3.githubusercontent.com/u/11672053?v=4","gravatar_id":"","url":"https://api.github.com/users/reseul","html_url":"https://github.com/reseul","followers_url":"https://api.github.com/users/reseul/followers","following_url":"https://api.github.com/users/reseul/following{/other_user}","gists_url":"https://api.github.com/users/reseul/gists{/gist_id}","starred_url":"https://api.github.com/users/reseul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reseul/subscriptions","organizations_url":"https://api.github.com/users/reseul/orgs","repos_url":"https://api.github.com/users/reseul/repos","events_url":"https://api.github.com/users/reseul/events{/privacy}","received_events_url":"https://api.github.com/users/reseul/received_events","type":"User","site_admin":false},"body":"- Code supports multiple top level CoreApplicationView views (each with its own dispatcher thread) in UWP. \r\n- There is still a \"main dispatcher\" corresponding to the MainView.Dispatcher. Lifecycle events should still be delivered on this dispatcher by the hosting app.\r\n- Entry-point wise the old mechanisms (ReactPage & ReactNativeHost) still work as one view solutions. \r\nThose who want to go mutli-view have to use ReactNativeAppHost and per root view ReactNativeViewHost (one CoreApplicationView can contain more than one root view).\r\n- All the root views share same instance of JS engine.\r\n- The initialization of the shared ReactContext/ReactInstance/ReactBridge/etc. is serialized through an awaitable lock and is done on main dispatcher only.\r\n- One UIViewOperationQueueInstance (renamed from UIViewOperationQueue) is created for each dispatcher thread. Each of these have dedicated ReactChoreographer and NativeViewHierarchyManager objects, all confined within the respective dispatcher threads.\r\nThe containing files will be renamed after the review.\r\n- View managers are customarily thread safe since they are basically stateless. There are small exceptions (like same statics used for perf reasons) that had to be addressed.\r\nSame goes with statics in ViewManagersPropertyCache and PropertySetter.\r\n- Made threading in shadow registry more consistent: AddRootNode is now called on layout manager thread, same as with the other methods. Removed some locking that is not needed anymore.\r\n- Reshuffled DispatcherHelpers a little:\r\n\t- RunOn* methods are now fire and forget \"private void\" (no one awaits them throughout the code), with a continuation that logs the after the fact errors.\r\n\t- Both RunOn* and CallOn* support now an \"allowInline\" parameter.\r\n- Will update doc if needed (not covered yet, until we go through this review)\r\n- I locally have a heavily modified Playground to test all scenarios, but I'll leave the repo Playground as is. I'll move a lot of those changes to RNTester later.\r\n\r\n\r\n","created_at":"2018-02-03T04:14:15Z","updated_at":"2018-02-05T18:58:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"67a8e29a0a785c4f47cc3c54cd7532bebd9c312e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615/commits","review_comments_url":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615/comments","review_comment_url":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/react-native-windows/issues/1615/comments","statuses_url":"https://api.github.com/repos/Microsoft/react-native-windows/statuses/703fa54a4c16b399cefbf2adc09eabde6ed094b6","head":{"label":"reseul:multi_window","ref":"multi_window","sha":"703fa54a4c16b399cefbf2adc09eabde6ed094b6","user":{"login":"reseul","id":11672053,"avatar_url":"https://avatars3.githubusercontent.com/u/11672053?v=4","gravatar_id":"","url":"https://api.github.com/users/reseul","html_url":"https://github.com/reseul","followers_url":"https://api.github.com/users/reseul/followers","following_url":"https://api.github.com/users/reseul/following{/other_user}","gists_url":"https://api.github.com/users/reseul/gists{/gist_id}","starred_url":"https://api.github.com/users/reseul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reseul/subscriptions","organizations_url":"https://api.github.com/users/reseul/orgs","repos_url":"https://api.github.com/users/reseul/repos","events_url":"https://api.github.com/users/reseul/events{/privacy}","received_events_url":"https://api.github.com/users/reseul/received_events","type":"User","site_admin":false},"repo":{"id":113353887,"name":"react-native-windows","full_name":"reseul/react-native-windows","owner":{"login":"reseul","id":11672053,"avatar_url":"https://avatars3.githubusercontent.com/u/11672053?v=4","gravatar_id":"","url":"https://api.github.com/users/reseul","html_url":"https://github.com/reseul","followers_url":"https://api.github.com/users/reseul/followers","following_url":"https://api.github.com/users/reseul/following{/other_user}","gists_url":"https://api.github.com/users/reseul/gists{/gist_id}","starred_url":"https://api.github.com/users/reseul/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reseul/subscriptions","organizations_url":"https://api.github.com/users/reseul/orgs","repos_url":"https://api.github.com/users/reseul/repos","events_url":"https://api.github.com/users/reseul/events{/privacy}","received_events_url":"https://api.github.com/users/reseul/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/reseul/react-native-windows","description":"A framework for building native UWP and WPF apps with React.","fork":true,"url":"https://api.github.com/repos/reseul/react-native-windows","forks_url":"https://api.github.com/repos/reseul/react-native-windows/forks","keys_url":"https://api.github.com/repos/reseul/react-native-windows/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reseul/react-native-windows/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reseul/react-native-windows/teams","hooks_url":"https://api.github.com/repos/reseul/react-native-windows/hooks","issue_events_url":"https://api.github.com/repos/reseul/react-native-windows/issues/events{/number}","events_url":"https://api.github.com/repos/reseul/react-native-windows/events","assignees_url":"https://api.github.com/repos/reseul/react-native-windows/assignees{/user}","branches_url":"https://api.github.com/repos/reseul/react-native-windows/branches{/branch}","tags_url":"https://api.github.com/repos/reseul/react-native-windows/tags","blobs_url":"https://api.github.com/repos/reseul/react-native-windows/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reseul/react-native-windows/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reseul/react-native-windows/git/refs{/sha}","trees_url":"https://api.github.com/repos/reseul/react-native-windows/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reseul/react-native-windows/statuses/{sha}","languages_url":"https://api.github.com/repos/reseul/react-native-windows/languages","stargazers_url":"https://api.github.com/repos/reseul/react-native-windows/stargazers","contributors_url":"https://api.github.com/repos/reseul/react-native-windows/contributors","subscribers_url":"https://api.github.com/repos/reseul/react-native-windows/subscribers","subscription_url":"https://api.github.com/repos/reseul/react-native-windows/subscription","commits_url":"https://api.github.com/repos/reseul/react-native-windows/commits{/sha}","git_commits_url":"https://api.github.com/repos/reseul/react-native-windows/git/commits{/sha}","comments_url":"https://api.github.com/repos/reseul/react-native-windows/comments{/number}","issue_comment_url":"https://api.github.com/repos/reseul/react-native-windows/issues/comments{/number}","contents_url":"https://api.github.com/repos/reseul/react-native-windows/contents/{+path}","compare_url":"https://api.github.com/repos/reseul/react-native-windows/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reseul/react-native-windows/merges","archive_url":"https://api.github.com/repos/reseul/react-native-windows/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reseul/react-native-windows/downloads","issues_url":"https://api.github.com/repos/reseul/react-native-windows/issues{/number}","pulls_url":"https://api.github.com/repos/reseul/react-native-windows/pulls{/number}","milestones_url":"https://api.github.com/repos/reseul/react-native-windows/milestones{/number}","notifications_url":"https://api.github.com/repos/reseul/react-native-windows/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reseul/react-native-windows/labels{/name}","releases_url":"https://api.github.com/repos/reseul/react-native-windows/releases{/id}","deployments_url":"https://api.github.com/repos/reseul/react-native-windows/deployments","created_at":"2017-12-06T18:40:10Z","updated_at":"2017-12-06T18:40:13Z","pushed_at":"2018-02-05T17:35:25Z","git_url":"git://github.com/reseul/react-native-windows.git","ssh_url":"git@github.com:reseul/react-native-windows.git","clone_url":"https://github.com/reseul/react-native-windows.git","svn_url":"https://github.com/reseul/react-native-windows","homepage":"http://facebook.github.io/react-native/","size":156166,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"f2c688d50b0ca328d08ee07e193d4d69ba747a05","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":48009214,"name":"react-native-windows","full_name":"Microsoft/react-native-windows","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/react-native-windows","description":"A framework for building native UWP and WPF apps with React.","fork":false,"url":"https://api.github.com/repos/Microsoft/react-native-windows","forks_url":"https://api.github.com/repos/Microsoft/react-native-windows/forks","keys_url":"https://api.github.com/repos/Microsoft/react-native-windows/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/react-native-windows/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/react-native-windows/teams","hooks_url":"https://api.github.com/repos/Microsoft/react-native-windows/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/react-native-windows/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/react-native-windows/events","assignees_url":"https://api.github.com/repos/Microsoft/react-native-windows/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/react-native-windows/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/react-native-windows/tags","blobs_url":"https://api.github.com/repos/Microsoft/react-native-windows/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/react-native-windows/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/react-native-windows/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/react-native-windows/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/react-native-windows/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/react-native-windows/languages","stargazers_url":"https://api.github.com/repos/Microsoft/react-native-windows/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/react-native-windows/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/react-native-windows/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/react-native-windows/subscription","commits_url":"https://api.github.com/repos/Microsoft/react-native-windows/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/react-native-windows/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/react-native-windows/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/react-native-windows/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/react-native-windows/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/react-native-windows/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/react-native-windows/merges","archive_url":"https://api.github.com/repos/Microsoft/react-native-windows/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/react-native-windows/downloads","issues_url":"https://api.github.com/repos/Microsoft/react-native-windows/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/react-native-windows/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/react-native-windows/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/react-native-windows/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/react-native-windows/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/react-native-windows/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/react-native-windows/deployments","created_at":"2015-12-15T00:16:54Z","updated_at":"2018-02-05T16:40:14Z","pushed_at":"2018-02-05T17:35:26Z","git_url":"git://github.com/Microsoft/react-native-windows.git","ssh_url":"git@github.com:Microsoft/react-native-windows.git","clone_url":"https://github.com/Microsoft/react-native-windows.git","svn_url":"https://github.com/Microsoft/react-native-windows","homepage":"http://facebook.github.io/react-native/","size":158796,"stargazers_count":3485,"watchers_count":3485,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":292,"mirror_url":null,"archived":false,"open_issues_count":254,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":292,"open_issues":254,"watchers":3485,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615"},"html":{"href":"https://github.com/Microsoft/react-native-windows/pull/1615"},"issue":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/issues/1615"},"comments":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/issues/1615/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/pulls/1615/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/react-native-windows/statuses/703fa54a4c16b399cefbf2adc09eabde6ed094b6"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"reseul"}}