|
hello
i am working in windows application the problem is when I execute the exe file the application executes. Without closing the application again i try to execute the exe file my application executes. I cannot let it happen.. Kindly give some ideas so that i can rectify the problem
|
|
|
|
|
In the Main method, Use Process class to determine if an instance of your program is already running. If running then display an Error Message and Close. Otherwise start the Application.
USe the following method to test if the application is running.
public static bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
}
|
|
|
|
|
You can scan a list of processes but if someone renames the executable file that will not work. On the other hand using a mutex is much more reliable way of checking.
|
|
|
|
|
Hi,
use a Mutex to make your app "single instance". There are several CP articles on the subject, here is one[^] of them.
BTW: do not rely on process names, since they may be changed, and you might not get access to all of them.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
hi sir,
i am working on c# then problem create in datagridview.
so please help me. and my problem this datagridview inside combobox click open new form in c#.
so please help me
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:04am.
|
|
|
|
|
sir ,
any other solution in use for
1. datagridview click cell then display combobox and click combobox then open form inside the datagridview.
please help me
|
|
|
|
|
Hello,
Time to defer to the experts. I have a C# app and a native C++ function in a separate dll. I need to pass a portion of an array by reference to the native code. I've worked with P/Invoke a little bit, but it's still a bit new to me. I've found plenty to P/Invoke examples for passing a whole array, but I haven't found anything specifically for passing a portion of an array. The native function's signature is
void foo(int* arr, int length) and is meant to be called in native C++ like so:
for(int i = 0; i < length; i += stepSize)
{
foo(&arr[i], stepSize);
} I cannot modify the code for foo . From MSDN[^], it looks like to pass the entire array I would use
[DllImport( "nativeLib.dll")]
public static extern void foo([In, Out] int[] arr, int length); and I can call it as
foo(arr, arr.Length);
Now to my question (more like a sanity check). If I want to call foo as in the loop above, should my declaration be
[DllImport("nativeLib.dll")]
public static extern void foo(IntPtr arr, int length); and my call be
unsafe
{
IntPtr unmanagedArr = Marshal.AllocHGlobal(arr.Length * sizeof(int));
Marshal.Copy(arr, 0, unmanagedArr, arr.Length);
for(int i = 0; i < length; i += stepSize)
{
foo(new IntPtr(unmanagedArr.ToInt64() + i), stepSize);
}
Marshal.Copy(unmanagedArr, arr, 0, arr.Length);
Marshal.FreeHGlobal(unmanagedArr);
}
Thanks,
Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
dybs wrote:
unsafe
{
IntPtr unmanagedArr = Marshal.AllocHGlobal(arr.Length * sizeof(int));
Marshal.Copy(arr, 0, unmanagedArr, arr.Length);
for(int i = 0; i < length; i += stepSize)
{
foo(new IntPtr(unmanagedArr.ToInt64() + i), stepSize);
}
Marshal.Copy(unmanagedArr, arr, 0, arr.Length);
Marshal.FreeHGlobal(unmanagedArr);
}
Had some time to poke around a bit more and discovered the GCHandle class. My solution is
int[] managedInput = SomeFunctionThatReturnsAnIntArray();
GCHandle arrayHandle = GCHandle.Alloc(managedInput, GCHandleType.Pinned);
IntPtr arrayPtr = arrayHandle.AddrOfPinnedObject();
long arrayAddr = arrayPtr.ToInt64();
for(int i =0 ; i < length; i += stepSize)
{
foo(new IntPtr(arrayAddr + (i * sizeof(int))), stepSize);
}
arrayHandle.Free();
Not sure if the sizeof() part works the same on 32-bit and 64-bit systems, I'll be testing that tomorrow.
What I like about this solution is that I can pass in the address I get from my GCHandle and my managed arrays is directly updated. No calls to Marshal required! Hopefully I'm not missing anything like unsafe context or fixed statment (I think the GCHandleType.Pinned takes care of that). Hope this helps other people.
Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
my programe base on WinForm.
It has two buttons,one is "start" the other is "stop".
now i click the "start" button it will excute the code as below:
public void Polling()
{
try
{
...........
Thread[] mythread = new Thread[Count];
for (int i=0; i <Count;i ++)
{
mythread[i] = new Thread(new ParameterizedThreadStart(gatherOnlineTime));
....................
mythread[i].Start(obj);
}
}
catch
{
..............
}
}
now i want to click the button of "stop" to abort the running thread.
how to do it?
Any help will be appreciated!
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:04am.
|
|
|
|
|
thank you stancrm!
But the problem is how can i get the running thread's instance
when i click the other button "stop".
|
|
|
|
|
scoket wrote: Thread[] mythread = new Thread[Count];
Move this code outside the method, i.e., at the class level and use the array to access the threads from your stop method.
|
|
|
|
|
hello
my application is store the fingure print in mastercard , i used biotrust key and given sdk to store all details in mastercard., and also verification is completed . I want to read card data without a fingure verification. My client asked me , insert a card, it have a data inform the user through message
But i check the sdk not get the solution
using card ACOS3 -24
Anas
|
|
|
|
|
You're going to have to talk to the manufacturer of the SDK you're using about this. If it works liek I think it does, you can't get at the data without the print.
|
|
|
|
|
I have been looking for a plugin that generates webpages or help documents based on your content. I have found nDoc which really isn't supported anything as it doesn't even support v2.0, and SandCastle which only seems to have a plugin for Visual Studio 2005.
Well is there anything for Visual Studio 2008? I'm not having any luck finding some. I've been really bad at commenting stuff and I've read now on proper ways to do it lol.
So now I'm going back and doing it (I know, I know)
|
|
|
|
|
Any automatically generated comment is obviously useless, it represents what a piece of code could work out about your code by reading it. A human should be able to do the same. A good comment will describe something NOT clear from the code.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
And if you don't have the code...?
|
|
|
|
|
Why do you need documentation for code that doesn't exist ?
|
|
|
|
|
Because you got a DLL before the code disappeared.
|
|
|
|
|
I am commenting the code like I should be now. The problem is I am the only one that can program here. We don't really have a programming position. So if I leave they are screwed unless they happen to get a network admin that can write C# as well.
I am just trying to make it that much easier for them and was thinking a help file could help them edit small things if they need to in the future.
|
|
|
|
|
I was just running into the same thing today. Building help files that is, I commented my code properly the first time. Sandcastle with the Sandcastle Help File Builder[^] worked perfectly.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Perfect! That one looks great. I didn't find that version of Sandcastle.. didn't come with a GUI the one I downloaded.
Thanks Mark
|
|
|
|
|
Message Closed
modified 23-Nov-14 7:03am.
|
|
|
|
|
The files seem to be missing from that webpage
|
|
|
|