{"action":"created","issue":{"url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/issues/42","labels_url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/issues/42/labels{/name}","comments_url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/issues/42/comments","events_url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/issues/42/events","html_url":"https://github.com/SeriousM/WPFLocalizationExtension/issues/42","id":49595556,"number":42,"title":"Threading issue","user":{"login":"Rand-Random","id":9868626,"avatar_url":"https://avatars.githubusercontent.com/u/9868626?v=3","gravatar_id":"","url":"https://api.github.com/users/Rand-Random","html_url":"https://github.com/Rand-Random","followers_url":"https://api.github.com/users/Rand-Random/followers","following_url":"https://api.github.com/users/Rand-Random/following{/other_user}","gists_url":"https://api.github.com/users/Rand-Random/gists{/gist_id}","starred_url":"https://api.github.com/users/Rand-Random/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rand-Random/subscriptions","organizations_url":"https://api.github.com/users/Rand-Random/orgs","repos_url":"https://api.github.com/users/Rand-Random/repos","events_url":"https://api.github.com/users/Rand-Random/events{/privacy}","received_events_url":"https://api.github.com/users/Rand-Random/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/labels/Enhancement","name":"Enhancement","color":"009800"}],"state":"closed","locked":false,"assignee":{"login":"MrCircuit","id":1327734,"avatar_url":"https://avatars.githubusercontent.com/u/1327734?v=3","gravatar_id":"","url":"https://api.github.com/users/MrCircuit","html_url":"https://github.com/MrCircuit","followers_url":"https://api.github.com/users/MrCircuit/followers","following_url":"https://api.github.com/users/MrCircuit/following{/other_user}","gists_url":"https://api.github.com/users/MrCircuit/gists{/gist_id}","starred_url":"https://api.github.com/users/MrCircuit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrCircuit/subscriptions","organizations_url":"https://api.github.com/users/MrCircuit/orgs","repos_url":"https://api.github.com/users/MrCircuit/repos","events_url":"https://api.github.com/users/MrCircuit/events{/privacy}","received_events_url":"https://api.github.com/users/MrCircuit/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/milestones/2","labels_url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/milestones/2/labels","id":922948,"number":2,"title":"vNext","description":null,"creator":{"login":"SeriousM","id":462013,"avatar_url":"https://avatars.githubusercontent.com/u/462013?v=3","gravatar_id":"","url":"https://api.github.com/users/SeriousM","html_url":"https://github.com/SeriousM","followers_url":"https://api.github.com/users/SeriousM/followers","following_url":"https://api.github.com/users/SeriousM/following{/other_user}","gists_url":"https://api.github.com/users/SeriousM/gists{/gist_id}","starred_url":"https://api.github.com/users/SeriousM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SeriousM/subscriptions","organizations_url":"https://api.github.com/users/SeriousM/orgs","repos_url":"https://api.github.com/users/SeriousM/repos","events_url":"https://api.github.com/users/SeriousM/events{/privacy}","received_events_url":"https://api.github.com/users/SeriousM/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":3,"state":"open","created_at":"2015-01-05T23:07:05Z","updated_at":"2015-02-24T08:45:08Z","due_on":null,"closed_at":null},"comments":12,"created_at":"2014-11-20T18:02:14Z","updated_at":"2015-02-24T10:06:06Z","closed_at":"2015-02-24T08:45:08Z","body":"Hi.\r\n\r\nI have a little annoying problem with opening new windows in separate threads, have a look at the following setup.\r\n\r\nThis is my Window XAML:\r\n```\r\n<Window xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\r\n        xmlns:lex=\"http://wpflocalizeextension.codeplex.com\"\r\n        x:Class=\"WpfApplication1.Window1\"\r\n        Height=\"100\"\r\n        Width=\"100\"\r\n        lex:LocalizeDictionary.DesignCulture=\"de\">\r\n    <StackPanel Orientation=\"Vertical\">\r\n        <Button Click=\"NewWindowHandler\"\r\n                Content=\"newwindow\"></Button>\r\n        <TextBlock Text=\"{lex:Loc WpfApplication1:Strings:HelloWorld}\"></TextBlock>\r\n    </StackPanel>\r\n</Window>\r\n```\r\nAnd this is the code behind:\r\n\r\n```\r\nprivate void NewWindowHandler(object sender, RoutedEventArgs e)\r\n{\r\n    Thread newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));\r\n    newWindowThread.SetApartmentState(ApartmentState.STA);\r\n    newWindowThread.IsBackground = true;\r\n    newWindowThread.Start();\r\n    newWindowThread.Join();\r\n}\r\n\r\nprivate void ThreadStartingPoint()\r\n{\r\n    Window1 tempWindow = new Window1();\r\n    tempWindow.Closed += tempWindow_Closed;\r\n    tempWindow.Show();\r\n    System.Windows.Threading.Dispatcher.Run();\r\n}\r\n\r\nprivate void tempWindow_Closed(object sender, EventArgs e)\r\n{\r\n    (sender as Window).Dispatcher.InvokeShutdown();\r\n}\r\n```\r\n\r\nWhen you run this application and hit the button you will notice that no second window shows up, if you remove the line lex:LocalizeDictionary.DesignCulture=\"de\" the window will show.\r\n\r\n\r\nAnother issue I am facing is a little more complicated.\r\nImagine you have 3 windows.\r\n1. Window - is the main window application starts with it\r\n2. Window gets opened in a separate thread\r\n3. Window gets opened after 2nd Window gets closed in the UI thread again, this window also has a UserControl in it\r\n\r\nUpon opening the 3rd Window with the usercontrol application crashes telling me I am accessing something from a different thread.\r\n\r\nThis is the code to reproduce:\r\n(Notice that Window2/3 and UserControl have nothing is codebehind)\r\n(To reproduce you have to hit the button in Window1 2 times - 1 hit opens Window2 and than Window3 - Window3 will cause the crash)\r\n\r\nWindow1 XAML:\r\n```\r\n<Window xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\r\n        xmlns:lex=\"http://wpflocalizeextension.codeplex.com\"\r\n        x:Class=\"WpfApplication4.Window1\"\r\n        Height=\"200\"\r\n        Width=\"200\">\r\n    <StackPanel Orientation=\"Vertical\">\r\n        <Button Click=\"NewWindowHandler\"\r\n                Content=\"newwindow\"></Button>\r\n        <TextBlock Text=\"{lex:Loc WpfApplication4:Strings:HelloWorld}\"></TextBlock>\r\n    </StackPanel>\r\n</Window>\r\n\r\n```\r\n\r\nWindow1 Code Behind:\r\n```\r\nprivate int _counter = 0;\r\nprivate void NewWindowHandler(object sender, RoutedEventArgs e)\r\n{\r\n    _counter++;\r\n\r\n    if (_counter == 1)\r\n    {\r\n        var newWindowThread = new Thread(OpenWindow2);\r\n        newWindowThread.SetApartmentState(ApartmentState.STA);\r\n        newWindowThread.IsBackground = true;\r\n        newWindowThread.Start();\r\n        newWindowThread.Join();\r\n        return;\r\n    }\r\n\r\n    if (_counter == 2)\r\n    {\r\n        OpenWindow3();\r\n        return;\r\n    }\r\n\r\n    Application.Current.Shutdown();\r\n    return;\r\n}\r\n\r\nprivate void OpenWindow2()\r\n{\r\n    var tempWindow = new Window2();\r\n    tempWindow.Closed += tempWindow_Closed;\r\n    tempWindow.Show();\r\n    System.Windows.Threading.Dispatcher.Run();\r\n}\r\n\r\nprivate void OpenWindow3()\r\n{\r\n    var tempWindow = new Window3();\r\n    tempWindow.Show();\r\n}\r\n\r\nprivate void tempWindow_Closed(object sender, EventArgs e)\r\n{\r\n    (sender as Window).Dispatcher.InvokeShutdown();\r\n}\r\n```\r\n\r\nWindow2 XAML:\r\n```\r\n<Window xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\r\n        xmlns:lex=\"http://wpflocalizeextension.codeplex.com\"\r\n        x:Class=\"WpfApplication4.Window2\"\r\n        Height=\"200\"\r\n        Width=\"200\">\r\n    <StackPanel Orientation=\"Vertical\">\r\n        <TextBlock Text=\"{lex:Loc WpfApplication4:Strings:HelloWorld2}\"></TextBlock>\r\n    </StackPanel>\r\n</Window>\r\n```\r\n\r\nWindow3 XAML:\r\n```\r\n<Window xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n        xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\r\n        xmlns:lex=\"http://wpflocalizeextension.codeplex.com\"\r\n        xmlns:wpfApplication4=\"clr-namespace:WpfApplication4\"\r\n        x:Class=\"WpfApplication4.Window3\"\r\n        Height=\"200\"\r\n        Width=\"200\">\r\n    <StackPanel Orientation=\"Vertical\">\r\n        <Button Content=\"newwindow\"></Button>\r\n        <TextBlock Text=\"{lex:Loc WpfApplication4:Strings:HelloWorld3}\"></TextBlock>\r\n        <wpfApplication4:UserControl1></wpfApplication4:UserControl1>\r\n    </StackPanel>\r\n</Window>\r\n```\r\n\r\nUserControl XAML:\r\n```\r\n<UserControl x:Class=\"WpfApplication4.UserControl1\"\r\n             xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n             xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\r\n             xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"\r\n             xmlns:d=\"http://schemas.microsoft.com/expression/blend/2008\"\r\n             mc:Ignorable=\"d\"\r\n             xmlns:lex=\"http://wpflocalizeextension.codeplex.com\">\r\n    <Grid>\r\n        <Label Content=\"{lex:Loc WpfApplication4:Strings:HelloWorld}\"\r\n               Margin=\"5\"\r\n               Grid.Row=\"0\"\r\n               Grid.Column=\"0\"\r\n               VerticalAlignment=\"Center\"\r\n               Target=\"{Binding ElementName=txtAccNr}\" />\r\n    </Grid>\r\n</UserControl>\r\n```\r\n\r\nThe things I noticed so far:\r\n1. If Window2 has no lex:loc, Window3 opens\r\n2. If Window3 has no usercontrol it opens\r\n\r\nHope everything is clear.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/issues/comments/75729452","html_url":"https://github.com/SeriousM/WPFLocalizationExtension/issues/42#issuecomment-75729452","issue_url":"https://api.github.com/repos/SeriousM/WPFLocalizationExtension/issues/42","id":75729452,"user":{"login":"SeriousM","id":462013,"avatar_url":"https://avatars.githubusercontent.com/u/462013?v=3","gravatar_id":"","url":"https://api.github.com/users/SeriousM","html_url":"https://github.com/SeriousM","followers_url":"https://api.github.com/users/SeriousM/followers","following_url":"https://api.github.com/users/SeriousM/following{/other_user}","gists_url":"https://api.github.com/users/SeriousM/gists{/gist_id}","starred_url":"https://api.github.com/users/SeriousM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SeriousM/subscriptions","organizations_url":"https://api.github.com/users/SeriousM/orgs","repos_url":"https://api.github.com/users/SeriousM/repos","events_url":"https://api.github.com/users/SeriousM/events{/privacy}","received_events_url":"https://api.github.com/users/SeriousM/received_events","type":"User","site_admin":false},"created_at":"2015-02-24T10:06:06Z","updated_at":"2015-02-24T10:06:06Z","body":":clap: :clap: :clap: "}}