I have a WinForms C# .NET 4.5.2 OWIN self hosted server that uses a signalr hub. In this same WinForm project I start the signalr hub as follows:
private void Form1_Load(object sender, EventArgs e) {
hubConnection = new HubConnection("http://localhost:12345/", clientParams);
hubProxy = hubConnection.CreateHubProxy("OfmControl");
hubProxy.On("Message", message => onData(message));
hubConnection.Start();
My onData method looks like this:
private void onData(dynamic message)
{
var file = new System.IO.FileInfo(message);
playVideo(file.FullName);
}
playVideo method looks like this:
private void playVideo(string file)
{
int tc6 = 0;
try
{
axWMPn[0].URL = file;
}
catch (System.Runtime.InteropServices.COMException comEx)
{
Console.WriteLine("playVideo COMException 0: " + comEx.Source + " -- " + comEx.Message);
}
}
axWMPn is an activex Windows Media Player object on the main form. When I run a separate C# signalr client program and send a filename message to this OWIN signalr sever and onData receives the filename and assigns it to axWMPn[0] per above code it always works never hits catch exception never receive a cross thread exception? I have run it hundreds of times never once received a cross thread exception and always works? But if I do the following I receive a cross thread exception every time obviously:
private void onData(dynamic message)
{
textBox1.text = message; ---> cross thread exception everytime here
var file = new System.IO.FileInfo(message);
playVideo(file.FullName);
}
I started thinking what I am doing is a cross thread violation but why does it always work why am I not receiving a thread violation in Visual Studio when I run the project in debug mode like I always do when I attempt to assign textBox1.text in onData? I have a feeling it has something to do with axWMP being an activex COM object but still seems I should eventually have a cross thread exception on this if it is?
If it is a cross thread violation do I need to do a BeginInvoke/Invoke around axWMPn[0] assignment? Thanks for any advice...