|
I have done a project in .net. I want that when a user tries to run the .exe, if it is already running then the same instance should be focused and no new instance should be creaed.
what to do please let me know
|
|
|
|
|
check out this code
string aModuleName = system.Diagnostics.Process.GetCurrentProcess.MainModule.ModuleName;
string aProcName = System.IO.Path.GetFileNameWithoutExtension(aModuleName);
if (system.Diagnostics.Process.GetProcessesByName(aProcName).Length>1)
{
Application.Exit();
}
Navin
|
|
|
|
|
You can use a Mutex. Here is a piece of code that shows how to do it:
In program.cs:
<pre>
private static System.Threading.Mutex _mutex;
private const string _mutexName = "Company_Product_MUTEX";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//Allow only one instance for this app to be active
try
{
//try to open existing mutex
_mutex = System.Threading.Mutex.OpenExisting(_mutexName);
if (_mutex != null)
return; //exit program;
}
catch
{ //There was no existing mutex so create mutex
try
{
_mutex = new System.Threading.Mutex(true, _mutexName);
}
catch { };
}
Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
/// do rest of the code, like Application.Run() etc.
}
static void Application_ApplicationExit(object sender, EventArgs e)
{
//Release Mutex
if (_mutex != null)
{
_mutex.ReleaseMutex();
}
}
</pre>
That should do the trick.
|
|
|
|
|
Create a Mutex in the very first instance and if it already exists, then just quit your application. Some pseudocode:
if(!Mutex.Exists("SomeName"))
{
Mutex.Create("SomeName");
}
else
{
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Single Instance[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
hi
i want to access the serial port to send or read data from that.
in this case i want to use Win API in my application.
my application is written in C#.net and .Net frame work version is 1.1
in this version the namespace SerialPort is not worked.
thatway i want use Win API's to communicate the serial ports.
and also list of Win API which are useful to communicates the serial ports in C#.Net
or any one can send some example programs the serial ports in c#.
plz help
G.Prem Kamal
|
|
|
|
|
You could download Reflector, search for the SerialPort class, and check (or copy / paste) the work Microsoft has done on the new class.
|
|
|
|
|
What's wrong with the answers you got below ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
They weren't serfed up on a golden platter.
|
|
|
|
|
I want to implement a chess game in C# and make it interoperable in J2EE too.
|
|
|
|
|
I look forward to reading your CP article. It will be interesting to say the least. J2EE is a web framework, and Java is a different language. How do you hope to achieve it ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I want to write some Program which can control the behavior of Windows, things like Disabling Ctrl+Alt+Delete, hiding start menu. this stuff
so anyone can help me in this, or tell me where shall i start searching
|
|
|
|
|
This article has some cool stuff: Lock Windows Desktop[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Thank u, ur code exactely satisfy my needs, but i want to do this under .NET not in visual c++
|
|
|
|
|
I m trying to export data in excel sheet, Data are exported in excel perfectly but i have a price filed in it which will truncated by excel to the non zero digits, but i want to show price field upto 4 decimal places either zero comes after decimal. Data are export through store procedure, size of price is defined 4 decimal places in sp but still excel trucate it to the non zero digits, what should i do to resolve this issue.
Regards,
Raheel Iqbal
|
|
|
|
|
Either change the cell or column formatting to text,
or add a single quote to the cell before the number: '9432.5700
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
can anybody help me in developing an application like VNC(virtual network computing) in c#
prashanth
|
|
|
|
|
The question is very vague, but if you want an answer to it, the answer is no.
Anybody can't help you with that, as everybody doesn't have the knowledge required to contribute anything to the project. I am sure that somebody can help you, though.
If you want a more specific answer than that, you have to write a more specific question.
---
b { font-weight: normal; }
|
|
|
|
|
prashanthmaalay wrote: can anybody help me in developing an application like VNC(virtual network computing) in c#
Not a small task.
This article is C++, but it is a place to get started:
Remote Desktop Viewer Lite[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
hi,
iam writing one application using .Net(version 1.1),
in my application, i want to read and send data to one hardware unit through Serialport(rs-232).
i known to access serialport in C#
i directly use SerialPort namespace.
but iam using version 1.1 that namespace is not supported here.
plz help me how can i access the Win API in C# to access the serial port.
G.Perm Kamal
|
|
|
|
|
Simplest would be to use .NET 2 if you can.
There are some free coms drivers for .NET littered across the internet, one was provided by Sax a while ago, one was written by MS and included in the VB.NET Resource Kit and I'm sure there are one or two here.
Just do a Google.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
hi thanks for reply
but my company must use .net framework version 1.1 only .
now tell how can i use win32 API to access the serial port.
plz help me .
Hi,
Thanks, if u think it's good.
otherwise sorry.
|
|
|
|
|
premkamalg wrote: now tell
Ask nicely, we're giving up free time to help you here.
premkamalg wrote: win32 API
Have you tried searching for RS232 on CodeProject, there's a C++ article on how to use Win32 to access the serial port, it isn't too difficult to translate.
Also this[^] article may help you.
As I mentioned there was stuff given away by MS, Sax and a few others, just do a Google search.
Alternatively you can use Reflector to examine the code behind the System.IO.Ports namespace for information on how to write your own RS232 Library.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Sorry Mr. Ed.Poore and also thanks for u r suggestion.
i will go through that links (what you give ).
G.Premkamal
|
|
|
|
|
hi thanks for u r answer.
but i must us e.Net Framework 1.1 only
now tell how can i access the Win API's in my C# program
plz help
G.Prem Kamal
|
|
|
|