Click here to Skip to main content
15,888,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a situation where my application on first establishes a connection to the DB and does some startup routine using a login assembly and then the main user interface (of another assembly) is presented to the user. Now there is another part of my main application that presents another user interface to the user but this also first instantiate the login assembly and then does the same thing.
What I am trying to achieve is that whatever application I launch that uses login assembly they all just use the running instance of login assembly and don't launch new instance of login assembly.


The login assembly is not large but all other applications when launched have to login to the system first and then they display the application windows. So imagine I launch App1 it will first get instance of login assembly do the login and then launch the App1 window. Then I launch App2 it does the same thing; first get instance of login assembly do the login and then launch the App1 window.

One thing I missed in mentioning is that the once login is successful it leave a logon information window open to make certain information always available to the user.

Hence you can imagine App1, App2, App3 etc all leaving one instance of log information window open.

Which is why the idea is for every App to check if there is a running instance of Logon information and if found use it else create a new one.

What I have tried:

Singleton pattern based login assembly but every calling application still gets a new instance of the login assmelby
Posted
Updated 25-Mar-16 4:11am
v2
Comments
ZurdoDev 17-Mar-16 12:12pm    
How can we help?
Sascha Lefèvre 17-Mar-16 12:22pm    
Why would you want to do that? Is your login assembly that large that you need to conserve memory?
Member 10279542 18-Mar-16 2:52am    
The login assembly is not large but all other applications when launched have to login to the system first and then they display the application windows. So imagine I launch App1 it will first get instance of login assembly do the login and then launch the App1 window. Then I launch App2 it does the same thing; first get instance of login assembly do the login and then launch the App1 window.

One thing I missed in mentioning is that the once login is successful it leave a logon information window open to make certain information always available to the user.

Hence you can imagine App1, App2, App3 etc all leaving one instance of log information window open.

Which is why the idea is for every App to check if there is a running instance of Logon information and if found use it else create a new one.
Sergey Alexandrovich Kryukov 25-Mar-16 0:43am    
Will you take a look at my second answer (Solution 2)? This is a really interesting topic. I just prepared the code for an article, but provide a full preview source code. I think it's interesting enough (short description of the idea can be found in Solution 1.)
—SA
CHill60 17-Mar-16 13:16pm    
Does this article help? Inter-Process Communication in .NET Using Named Pipes, Part 1[^]
or if both assemblies are in the same executable - Friend Assemblies (C# and Visual Basic)[^]

Too bad I don't have anything ready for publishing at the moment, but I have a very accomplished and lean single-instance system, which also passes command-line argument to an original instance, really guarantees uniqueness, and so on. Perhaps my short description can help you:

Enter multiple commands to only one process instance[^],
Custom Windows right-click command launching multiple instances[^].

If you have any questions, I'll gladly try to answer.

—SA
 
Share this answer
 
v2
Comments
[no name] 17-Mar-16 19:09pm    
Boah! a Little compensation :(
Sergey Alexandrovich Kryukov 17-Mar-16 19:19pm    
Thank you, Bruno.
As you can see, someone follows all my posts methodically. It's getting funny.
—SA
Sergey Alexandrovich Kryukov 25-Mar-16 0:38am    
By the way, please see my Solution 2. I finally created a separate utility suitable for publishing and uploaded my preview source code. Please see; I think it's interesting enough.

And I prepared the Free Pascal analog of it, which is much, much more compact than .NET version. As a Delphi developer, you might be interested. This is a topic for another article.

—SA
Maciej Los 18-Mar-16 18:22pm    
5ed!
Sergey Alexandrovich Kryukov 18-Mar-16 18:25pm    
Thank you, Maciej.
By the way, I just wrote a Free Pascal variant of the same thing, in just an hour or so, it turns out very compact, still dual-purpose (exiting on first instance check and passing command line). Would be good to publish, anyway, just needs time.
—SA
All right, here is my second answer, with more detail for you. I've done some work to generalize my solution I described earlier, to make it customizable and usable with all kinds of interactive applications.

In the meanwhile, you can see full preview source code, complete with UI demo. I hope everything is clear: S.A.Kryukov-SingleApplicationInstance.dotNet.src.zip (11.6 KB).

Later on, I'll write a formal article using this code. If you have some questions before I'm done, I'll try to answer.


[EDIT]

New updated solution is ready, in my new article: All Three Features of Single-Instance Applications at One Shot, .NET.

Importantly, this solution is different from what I temporarily published. In new version, I seriously took care about its portability. Now it should work correctly (via alternative CLR implementation, first of all, Mono) on non-Microsoft platforms, in particular, based on UNIX-like OS.

—SA
 
Share this answer
 
v5
Comments
Maciej Los 25-Mar-16 2:38am    
5+ for effort!
Sergey Alexandrovich Kryukov 25-Mar-16 2:48am    
Thank you, Maciej.
—SA
[no name] 25-Mar-16 8:15am    
I did not downloaded it, but I trust in you. So a 5 from my side.
Bruno
Sergey Alexandrovich Kryukov 25-Mar-16 9:52am    
Thank you, Bruno.
—SA
[no name] 25-Mar-16 10:11am    
It is sad that somebody voted again against you without giving a comment... I wish that CP changes the rules: If you downvote you have to give a comment... and as a consequence, the vote is known.
Bruno

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900