Hi all,
I’ve built a simple web app. which opens a local serial port on the server PC & communicates with a device which is connected to the serial port.
The serial port is opened during the Window1_Load() event and then a BackGroundWorker is started.
The device data is collected within the BackGroundWorker continuous loop and shown in a label every second or so.
All good and works when I run it within Visual Studio.
Now, I can open this app. in a remote browser (another PC), and this seems to continue to work but I’m confused as to why it does.
I would expect that every new browser connection I make would run a new Window1_Load() event where an attempt to open the same port would fail (because port is already being used).
Instead, the remote browser seems to show the device data OK.
I’m completely confused and obviously not understanding the basics of what’s going on here.
What I want to happen is that the serial communications be performed by a “master” process which is only called once, and all client connections are simply a viewer of what’s going on in the master process.
Can someone please explain to me how I go about achieving this?
Something else is strange. Despite stopping the Visual Studio project, the remote client continues to run!? whereas I would expect it to stop once the project has stopped!?
Thank you
Regards,
Darren
Hi all,
Just a small note on the side, so we can understand each other.
This is not obvious but “static” in C# translates to different things in VB.NET, depending on what we are referring to, a class or a variable (field/property).
In C#
public static class Customer
in VB.NET is
Public NotInheritable Class Customer
In C#
private static int nextId = 0;
in VB.NET is
Private Shared nextId As Integer = 0
So putting it all together, in C#
public static class Customer
{
private static int nextId = 0;
}
becames in VB.NET
Public NotInheritable Class Customer
Private Shared nextId As Integer = 0
End Class
When a new client connection is made, I understand that a new instance of the web app is created – and all variables within it are new & initialized within in the instance.
I don’t get how shared variables (within a vb module for example) aren’t also initialized For each app instance/session?
What makes shared variables different to non-shared in this context?
Hi,
I’m being stupid… AGAIN. Making silly mistakes that only a hardened desktop developer would make.
The local serial comms. must only be performed by ONE (the first) client connection. Each subsequent connection must not try to perform the same comms., but should be able to read the results of the comms. being performed by the first connection.
So, “somehow” I need to:
1) make the first connection aware that it is the first connection (the master, if you like), & perform the comms.
2) make each subsequent connection aware it is not the first (master), therefore don’t perform the comms but rather get the data from “somewhere else”.
With the above in mind, what would be a suitable method for the master to store the data for the other sessions? A text file? (Not a database at this stage)
Thanks
Darren
Darren,
I have a similar app that uses a single tcp connection to talk to monitoring probes. The way I constructed this in WiseJ was to create the tcp connection class as a static in the window_load event – that way there is only ever one connection in the scope of my application (except when the app pool recycles so you may end up with two copies so you will need some code to deal with failures and reconnections).
My tcp class raises events which my windows subscribe too in order to see the probe responses.
Your app will continue to run after stopping debug in Visual Studio because IISExpress continues to run – if you look in the apptray you can see the icon. Stop IISExpress and your app will stop.
HTH
Nic
Please login first to submit.