Appication is restarted continually in an application ported from Windows Forms

0
1

As the title says, I have the problem that the form defined in the start module and called by the Show() method is shown fine, but the Main() method is called again then in an endless loop.

I have checked carefully by comparing to a new and correctly working application from the Wisej templates; Default.json, Default.html, Startup.vb, web.config… no difference.

Also, I have created a simple new Form from scratch with two controls to be shown at startup; same behaviour.

The IISexpress log shows nothing suspicious; simply a “GET” http://localhost:5000/ at the beginning of each loop.

 

I’m really stuck here; any help is higly appreciated! Thanks!

 

  • You must to post comments
0
0

Hi Robert,

By any chance, are you writing/rewriting a file that happens to be inside the “bin” folder?

Usually, the app will keep restarting whenever a file is either written or overwritten inside of the bin folder.

Best,

Alaa

  • Robert Langer
    Ah, that’s interesting! Indeed, the Access database file is in the bin\ folder (for historic reasons), and there will happen writes for sure! This might well explain the behaviour I see. I will move it out of the bin\ folder. Thanks a lot!
  • You must to post comments
1
0

In the meantime, I could narrow down the issue to the code executed before the form is shown. Here, a database query (Access DB) is made to get some basic information the application uses. If this query is skipped, the form shows up corrently without restarting. The query is executed and populates an array without error. Question: Is it possible in a Wiesej application, to have some global data in the Module where also the Main() method resides? The mentioned array is also declared here.

Wisej version is 3.2.5; I’m running from Visual Studio 2022.

Any other ideas what causes this issue? Thanks!

  • Julie (ITG)
    Which Main() method are you referring to? There is Startup.cs (or Startup.vb), which contains a Main method (Startup.Main). There is also Program.cs (or Program.vb) which also contains a Main method (Program.Main). Startup.Main runs only once when the server starts. Program Main is executed once for each session. You could try setting a public variable to store your array in the Page1_Load() event handler (or Window1_Load() or Form1_Load()- name depends on what you named your form.). That is generally where I put code that gets data from a database and stores it in an array.
  • Robert Langer
    I was referring to Main() in Program.vb. Is it good practice to store global variables for a session here? Can they be referenced from e.g. the Forms? I’d like to separate data access etc from the forms, as it is good practices IMO.
  • Julie (ITG)
    So, if you were going to add global variables, Main() in Program.vb would be the place to put them. However, global variables are shared between all sessions so they are a bad idea. Remember,that each browser tab that has the Wisej application open is a new session. So, if you click on a button that changes a global variable, all the other sessions would have that value changed. It’s recommended to use session variables instead. https://docs.wisej.com/docs/controls/general/application#session-object
  • You must to post comments
0
0

What version of Wisej are you using?
Can you provide a sample so that we can try to reproduce? You mentioned that you created a simple new Form from scratch with two controls to be shown at startup-can you zip that and attach that to this forum post?

Is this a deployment, or are you just running it from Visual Studio?

-Julie

 

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.