How to limit the number of concurrent users of an app

jlmacdonald

Member
Joined
Apr 16, 2007
Messages
7
Programming Experience
1-3
Hello all,

I have an app that is currently functional released but our clients wish it to have some additional functionality implimented. Basically they want it to run on a couple of computers but only have one user use it at a time. (This app generates receipts numbers and so we only want want user at a time using it lest it give out incorrect receipt numbers.)

Currently I have some code implimented to check to see if the program is running but it will only look to see if it's running on that particular machine. This worked fine until we install it on other desktops.

In previous app I had a solution to this which seemed to work but I'm hoping that there is a more efficient way of doing this. Basically I had a SQL table that housed a GUID, username and timestamp. Upon startup the program would look in this table to see if there is a record present, if so it would generate a messagebox and then close. If there was no record then that would indicate that noone was using the program and would insert a record with the GUID, username and timestamp. Upon exiting the program, it would delete that record.

There was some arror trapping done just in case the program crashed so it wouldn't lock everyone out but I'm wondering if there's an easier way to do this? Can I make the program network aware to see if someone on the network is already running the app?

Like I said, the solution I came up with seemed to work but I was just wondering if there was a better, more efficient way of doing this.

Thanks for the help!
 
Currently I have a table that stores the Receipt Number so no matter where the program is run (or how many people are using it) it will always point back to that specific table.

Come to think of it, I'm going to check my code because as soon as a user enters an transaction it grabs the current receipt number from that table, increments it and saves the full transaction in a different table. Then the user will export the data as a text file so it can be imported into our accounting software and as long as I grab the receipt number from the dataset/datagrid that displays it, I should be all right.

I'm going to do some testing...I may not even have to do anything. I think I just answered my own question! :rolleyes:

Thanks for the help!

EDIT:
I just checked and that part will work fine but I guess the worry was in regards to the exporting of the file. We use the same filename to make it easier for the user to import and we don't want several users creating/overriding that particular file. So I guess I'm back in the same quandary.
 
Last edited:
hrm. well I'm having a little trouble understanding exactly what is going on. From what I can read it sounds like a group of users are using one folder for the storage of all the files.

Then you mention about ease of importing. I'm not sure what they are importing, but it leads me to one possible solution.

What if you take the file that is being generated and add this to your database. You still have a central repository and all users can access all the records created by all users. I'm not sure what type of file this is, but I figured it was just data that could be represented as a row in a table.

To export I would export locally on the users system. I would also use the Common SaveAs Dialog. You can prepopulate the name to whatever you'd like and let the user decide if they want to overwrite their file or rename it to something else.

Would this work for you?
 
you could always use your database to manage this, that's how a few application packages sort out user licenses (i.e. can't logon more than once with same username)

Do something like have a boolean value in a DB table, and when your application opens, have it connect to that table, and check to see if that value is True. If it is, return a messagebox to the user saying the program is already running. If it's false, carry on BUT set the value to True, so others can't connect.

Then, when your application is finally closed, set the value back to False...
 
Your tills are a bit too intelligent; all they should be doing is generating database entries. When the trime comes that you want to generate a file or report, have the database do it, rather than trying to collect all the files the tills have generated
 
But as he claimed, what will happen when the program crashes or when an user illegally closes the app (by clicking the X)?
In the database still this logged in mark is shown so the app then thinks someone is logged in and you cannot login again.

In our company we experience such problems also. What they then do is call IT and we manually reset this mark.
 
that's true, but in my app I've disabled the use of the close button, the user HAS to use the menu - for me; FILE -> Exit Application

I've done this for various reasons.

Instead of calling IT, you can create a simple admin form (password protected or user authentication), which will allow you to see what user is "locked" and reset them.
 
But as he claimed, what will happen when the program crashes or when an user illegally closes the app (by clicking the X)?
Clicking the [X] is not "illegally closing an app" - it simply closes the form, and if the application framework is enabled and "Quit when the startup form closes" and you closed the form that was nominated as the startup form then the app will quit. You get events fired when a form closes, so you would simply override the OnClosing method of the form (i.e. handling the closing event) and do your DB work in there

(n the database still this logged in mark is shown so the app then thinks someone is logged in and you cannot login again.

That's a consequence of crappy software design though. MSN Messenger doesnt whine at you if you sign in from home when your work is still logged on, it jsut disconnects the work one with a message "You have been disconnected from messenger because you signed in at another location" - you can do the same with databases quite easily
 
Thanks for all the help and sorry for the confusion. I lost sight at the task at hand for a little bit. The app that I have processes transactions and saves it to the DB. After the batch is completed the user will go and export a file that will be imported into our accounting software. The problem isn't so much as several people running the program at the same time because as soon as a transaction is completed, they click save and it saves to the DB right then and there as well as display in a datagrid view for them.

The file that is exported needs to be in one folder and named the same each time. This is where the concern is. If several people are exporting the file, it will get overridden. Our accounting software is rather old to put it mildly (it is DOS based) so that limits us in what we're able to do. When the user goes to import the transactions into the accounting software if defaults to a particular drive and filename, hence why we don't want to change the name and location of the export file.

In a previous app I built I implemented the database thing where upon app start up it would place a record in a table and delete it upon exiting. If someone else were to start up the program it would look in that db and not let the user in if there's a record in there. I can rehash that code and use it in this app without any problems. I just wasn't sure if there was a better way of doing this.

I also took into account most every situation I could think of that would lock a user out and in the several months that the other app was running only once it crashed and someone in IT had to go in the db an remove the record. I think that code is pretty bomb proof and has prooven itself so I can use that.
 
So how about this.

A second application runs that solely runs the import into the accounting app. What you can do is have another folder (Perhaps a sub folder of where your saving now) and store the files there as unique names. This second app will monitor for changes to this folder and when it detects a new file it copies it to the correct name and location, imports it into the accounting system and then grabs the next file. This allows you to have multiple users running and not have the file being overwritten.

Comments?
 
Back
Top