473,549 Members | 2,862 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Limit App to 1 Instance (Per File)?

I have a C# app that runs script files. The app is launched using a
command line argument to indicate which script should run. Most
scripts are run indefinitely in a loop and periodically perform tasks.
When the script is launched the Title Bar of the app indicates the name
of the app and the name of the script being run.

I thought to use a GetProcessesByN ame to return all instances of the
app and then to check the MainWindowTitle of each process to identify
that a script is running more than one instance. This almost works.
When the app is minimized, it runs in the system tray and the
MainWindowTitle returns and empty string.

While it is not difficult to prevent multiple instances of the app from
launching this is not the desired effect. The app may kick off any
number of instances. What matters is that the same script file is not
running under more than one instance of the app.

I realize I could record state information in a database or in a file
and check it upon launching the app, but there are timeliness issues
related to this approach -- the app may be too involved doing other
tasks to take the necessary time to update the state information for at
least several moments. Therefore, this approach is not
up-to-the-second accurate.

I considered checking scripts in and out. However, an abnormal
termination of the app may not properly check in a script as available.

Any ideas for making sure that only one instance of the app is running
any given script file?

Mario T. Lanza
Clarity Information Architecture, Inc.
2005.11

Nov 28 '05 #1
4 1413
Mutex' are used across application boundaries. Right before running a
script, make sure you can create a mutex for it with a valid return.
When the script is complete, close the Mutex.

Something like this:

bool okToRun;
Mutex m = new Mutex(true, myScriptName, out okToRun);
if (okToRun)
{
// run script here
m.Close();
m = null;
}

-Jerry

Nov 28 '05 #2
This is the first time I've heard anything about a "Mutex." I've just
now looked briefly into it and it seems like the right solution.
Thanks.

Nov 29 '05 #3
You may want to also append the app name to "myScriptNa me" just to make
sure it's unique (incase a script has a name that is the same as some
other mutex on your machine). Something like this works well:

Mutex m = new Mutex(true, "appname" + myScriptName, out okToRun);

je*****@san.rr. com wrote:
Mutex' are used across application boundaries. Right before running a
script, make sure you can create a mutex for it with a valid return.
When the script is complete, close the Mutex.

Something like this:

bool okToRun;
Mutex m = new Mutex(true, myScriptName, out okToRun);
if (okToRun)
{
// run script here
m.Close();
m = null;
}

-Jerry

Nov 29 '05 #4
Maybe it's enough to open the script file and lock it (FileShare.None ),
and close it after the script execution ends
I have a C# app that runs script files. The app is launched using a
command line argument to indicate which script should run. Most
scripts are run indefinitely in a loop and periodically perform tasks.
When the script is launched the Title Bar of the app indicates the name
of the app and the name of the script being run.

I thought to use a GetProcessesByN ame to return all instances of the
app and then to check the MainWindowTitle of each process to identify
that a script is running more than one instance. This almost works.
When the app is minimized, it runs in the system tray and the
MainWindowTitle returns and empty string.

While it is not difficult to prevent multiple instances of the app from
launching this is not the desired effect. The app may kick off any
number of instances. What matters is that the same script file is not
running under more than one instance of the app.

I realize I could record state information in a database or in a file
and check it upon launching the app, but there are timeliness issues
related to this approach -- the app may be too involved doing other
tasks to take the necessary time to update the state information for at
least several moments. Therefore, this approach is not
up-to-the-second accurate.

I considered checking scripts in and out. However, an abnormal
termination of the app may not properly check in a script as available.

Any ideas for making sure that only one instance of the app is running
any given script file?

Mario T. Lanza
Clarity Information Architecture, Inc.
2005.11

Nov 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2846
by: Tom Ostberg | last post by:
There appears to be a limit of ~16378 user Id's possible per database. When adding users we eventually get the message: > exec sp_adduser 'testUser', 'testUser', 'user_group' Server: Msg 15065, Level 16, State 1, Procedure sp_grantdbaccess, Line 160 All user IDs have been assigned. All of the MSSQL procedures eventually call...
1
1641
by: Jonathan & Maricel Espejo | last post by:
Hi, Could somebody confirm what is the maximum size of shared memory that can be allocated for DB2 on Windows 2000 Servers. I heard that its about 2GB. Is the 2GB shared memory limit applies to what per DATABASE or per INSTANCE? Your input would be highly appreciated. Regards, Maricel
2
5227
by: Dennis | last post by:
The documentation from M'soft for the limits on SQL Server DataBase is: "SQL Server can have as many as two billion tables per database and 1,024 columns per table. The number of rows and total size of the table are limited only by the available storage. The maximum number of bytes per row is 8,060. If you create tables with varchar,...
4
10763
by: Bill | last post by:
Hi, I would be grateful if someone could clarify my rather confused ideas of the 10 connection limit on XP/2000 when its being used as a server. (I realise that XP is really a client op sys with limited server capability, I am also aware you can kludge the number to 40, but assume I do not want to do that). As I understand it XP Pro will...
3
3136
by: sadanjan | last post by:
Hi , Appreciate if someone can clarify if database Share Memory Limit (2 GB ) in Unix 32 bit boxes is the top limit for all the databases put together in a database or is it for each of the database in an Instance Thanks & regards sadanjan
32
4028
by: Nu | last post by:
I want to protect myself from if someone with a fast connection hammers my site. It's not denial of service attacks, but offline downloaders (of course that don't show they're offline downloaders in the useragent so I can't filter them by that). My main issue is my site is PHP so if they hammer it, it gets all the PHP files executing and...
6
2986
by: Nosferatum | last post by:
Hi, on my Apache server I want to limit access to a certain file ouput (from php/MySQL) to just one IP. The idea is that users from another site should click a link whic redirects them to my special page on my server. Only those who access my page from one particulary URL are allowed to see my file. All others are denied. Is it possible to...
4
5788
by: Daniel | last post by:
is there some per-process-limit on memory in .net processes? is there any way to increase it? i keep getting System.OutOfMemoryException when my box has 8 gigs of unused memory.
4
2297
by: chemicalclothing | last post by:
Hi. I'm very new to Python, and so this is probably a pretty basic question, but I'm lost. I am looking to limit a float value to a number between 0 and 100 (the input is a percentage). I currently have: integer = int() running = True while running:
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7715
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7469
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.