 |
|
 |
"over-code"! Already implemented by VStudio
|
|
|
|
 |
|
 |
May I ask?
I've seen the option called "Make single instance application" in Project option page on Visual Studio's IDE.
Why don't we use the MS provided solution.
Are there anything differents?
Thank you,
Sek
|
|
|
|
 |
|
 |
definitely not! I would use the IDE's, no doubt. I think it is even better!
|
|
|
|
 |
|
 |
the author should just admit this article is close to useless and not mislead anyone, this is not the right way to implement a single instance, lets hope your dental skills are not like your programming skills or your ignorance of all the users comments here
sorry again I usually dont leave negative comments, but its your stubborn attitude that gets me most.
|
|
|
|
 |
|
 |
You are very prejudiced. I am professional for dental. This is not discussed here.
This article is my solution what you say to me.
Divinum est sedare dolorem
|
|
|
|
 |
|
|
 |
|
 |
You will see other user's processes and as a result it will not load. You will need to use a mutex instead.
This is for a winforms app and allows one instance per user so you may need to adjust mutex name to deal with sessions instead if a user has multiple desktops on citrix, but you can get the basic idea:
'Create a named mutex, named mutex's are visible throughout the system
'Named for APP and USER
SingleInstanceMutex = New Threading.Mutex(False, String.Concat(My.Application.Info.AssemblyName, System.Environment.UserName))
'See if we own the Mutex
If SingleInstanceMutex.WaitOne(0, False) = False Then
SingleInstanceMutex.Close()
SingleInstanceMutex = Nothing
MsgBox("Only one instance of this application may be run at a time.", MsgBoxStyle.Exclamation Or MsgBoxStyle.MsgBoxSetForeground Or MsgBoxStyle.OkOnly, System.Windows.Forms.Application.ProductName)
Environment.Exit(0)
End If
|
|
|
|
 |
|
 |
Use mutex instead of process list, it is the right solution for the problem, not checking list of running processes and it is really not understandable how such an example can get to best june code voting in codeproject.
The quality of codeproject is degrading constantly.
|
|
|
|
 |
|
 |
Poor code - not a solution.
|
|
|
|
 |
|
 |
I doesn't solve any problem. It doesn't allow parameter passing to the previous instance. The author stubbornly refuses to listen to advice.
|
|
|
|
 |
|
 |
Where is your advice or others? My ears are open on port 911
Divinum est sedare dolorem
|
|
|
|
 |
|
|
 |
|
 |
Do not ask a question; try ... if you discover; notify to us
Divinum est sedare dolorem
|
|
|
|
 |
|
 |
Poor code - not a solution.
|
|
|
|
 |
|
 |
it may be poor code (According to what?) but this is a solution with using Process Class not Mutex. As I said before... Here we do not discuss the best solution.
Divinum est sedare dolorem
|
|
|
|
 |
|
 |
Noone seems to take the time to explain the flaw.. I think there's a chance that if you start two 'protected' processes at the same time, they will both end up committing suicide. Another possible flaw is that if the results returned by GetProcessesByName are not perfectly in sync with the actual list of processes that you may end up with 2 or more processes running. Small chance, but still
|
|
|
|
 |
|
 |
Upon viewing the code it is immediatedly visible that your angle on this is flawed, therefore it's not even a solution let alone anywhere near the best!
You must be open to the advice of using a mutex to acheive this, for the sake of your users.
|
|
|
|
 |
|
 |
I do not agree with this approach for creating a Single Instance application. Here's the accurate way to do this.
public static void Main()
{
Mutex appSingleton = new System.Threading.Mutex(false, "MyAppSingleInstance");
if (appSingleton.WaitOne(0, false))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
appSingleton.Close();
}
Hope this helps..
|
|
|
|
 |
|
 |
A problem can be solved multiple ways. I do not agree your solution, too.
Divinum est sedare dolorem
|
|
|
|
 |
|
 |
Note that I've mentioned this as a better solution. In your solution it has a caveat of replicated process name. What if another process has the same name as your proces' name ?
|
|
|
|
 |
|
 |
Here we do not discuss the best solution. Thank you for sharing different solution with us.
Divinum est sedare dolorem
|
|
|
|
 |
|
 |
emarti wrote: Here we do not discuss the best solution.
In fact, we do
|
|
|
|
 |
|
 |
Your idea for the best?
Divinum est sedare dolorem
|
|
|
|
 |
|
 |
My a problem can be solved multiple ways, but there is a right way doing something ( which is in this case , aka Best Practice ) and a way which is buggy.
|
|
|
|
 |
|
 |
How can you send a message to the running instance, so that the already running instance knows that a new process is started and can do something with, for example, the arguments of the second process?
|
|
|
|
 |