All Answers

All Answers » Re: Local serial port / remote viewing » Comments for "Re: Local serial port / remote viewing"
  • Luca (ITG)
    Shared are static, they are initialized when the type is loaded (once per AppDomain) and shared among instances withing the same AppDomain. I sent a link to the .NET documentation regarding VB.NET Shared variables in a reply to the other post.
  • Darren
    Hi Luca, I understand how shared is used in traditional desktop apps, but there are mind-bending differences when it comes to web apps! I performed a simple experiment this afternoon in wisej to see how global (declared in vb module) variables behave & it seems that variables declared in a module maintain their value for every new client or session. Eh? Whatttt??? I wasn’t expecting that! I had a counter variable declared in a module, incrementing every second in a background loop. I then opened several browsers, both local & remote & this variable was the same value in all browsers. Mind… blown… So a vb module seems to be a place for global variables shared across all sessions. Please tell me this is the expected behaviour? Then I’ll be happy to accept it :-)
  • Tiago (ITG)
    VB “Shared” variables are what we call in c# “static” and are shared among all threads in the AppDomain. This means “Shared” variables have the same value in all Wisej session/instances. This is the expected behaviour..
  • Tiago (ITG)
    We call it “static” in C# because the value is the same for all instances of the class. But sometimes you need a variable to have a value shared among all instances of the class, but different on each Wisej session. In that case, you should store your value on a Session variable. See https://wisej.com/docs/html/Session.htm for details.
  • Darren
    Hi Tiago, Thanks, but my issue is not with the terminology or differences between VB & C#, it is with the scope of variables within a web app. Web app variable scope seems to be different to traditional desktop apps. For example, a traditional desktop app. may have a variable declared in a module. This variable is global to the app. instance ONLY. If you run another instance of the app., then that will have it own instance of the variable. With web apps., this is not so – it seems. A global variable (in a VB module) is global not just to the session, but ALL sessions – this is what was throwing me. I expected each session to have it’s own instance of the global variables. Am I correct? Thanks
  • Matthew Ferry
    Hi Darren – I like to look at it this way. Think of the web app running in IIS as a single instance of a desktop app – but magically multiple people can use that same instance, i.e. when a new user starts up the app – they are using the same instance you are already using. I’m a hardened desktop developer too – and only a squishy web developer, and it took me a while to get my head around that too.
  • Darren
    Hi Mathew, Your post has confused me even further, lol. The trouble is I’m not getting enough time to experiment at the moment. Let’s face it – best way to learn is to experiment. What I found last week was that variables declared in a vb module are shared between all clients/sessions. This is completely alien to the desktop developer &, as far as I know isn’t actually documented? It would great if there was a document which details the scope of variables in a wisej app.? What happens if multiple clients try to change the variable at the same time? Ugghhh… head spinning!