I have WPF applications. I this application I am dynamically adding WebBrowser controls. A signalR chat websites renders in WebBrowser control. The issue is only one hub connection made at a time in WPF. For eg if I have two WebBrowser controls in WPF, One will able to connect to hub and second will fail. But when I open two tabs in IE, both tabs able to make connection to hub. Please help
Update: Given bellow is example with demo code I created:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<TabControl x:Name="tabBrowsers" TabStripPlacement="Top" >
<TabItem Header="IM 1">
<WebBrowser x:Name="myBrowser1" Source=“URL of hub” Height="100" HorizontalAlignment="Left" Margin="5,33,0,0" VerticalAlignment="Top" Cursor="Arrow" />
</TabItem>
<TabItem Header="IM 2”>
<WebBrowser x:Name="myBrowser2" Source=“URL of hub” Height="100" HorizontalAlignment="Left" Margin="5,33,0,0" VerticalAlignment="Top" Cursor="Arrow" />
</TabItem>
</TabControl>
<Separator Height="100" Background="Transparent"/>
</StackPanel>
</Window>
Hub connection Javascript code:
$.connection.hub.start().done().fail();
So in this above demo code, myBrowser1 will able to connect to hub but not myBrowser2.
I further investigated and found that if I run two browser controls in two separate WPF application then both are able to connect to hub successfully. After these tests, My assumption is that SignalR restrict single hub connection per exe/process. I hope there is some way to overcome this.
Edit: I found that given bellow code helps me to create the connection.
`$.connection.hub.start({json: true})`
I also changed the settings in startup.cs
file to EnableJSONP = true
This works may be due to WPF uses IE as engine for its web browser control. But I am not able to send messages from both tabs with web browsers controls. I am receiving messages but not able to send them.
Edit: I found a question which also had similar issue like me. Second WebBrowser control with SignalR freezes javascript