|
Erick Kinnee wrote: IS there a less memory leaky and faster way to do this? No idea. That's what development is about, finding the answers.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
What is "over usage"? My apps are using a lot of ints, do you think it could leak memory due to that? It won't, and speed is not an indication for a memory-leak. The amount of used memory is an indication.
A few remarks on the code;
if (member.SchemaClassName == "Group")
{
object admMembers = member.Invoke("members", null);
foreach (object admMember in (IEnumerable)admMembers)
{
DirectoryEntry membername = new DirectoryEntry(admMember);
DataRow dr = table.NewRow();
dr["Machine"] = remMachine.Name.ToString();
dr["Group"] = member.Name.ToString();
dr["User"] = membername.Name.ToString();
table.Rows.Add(dr);
membername.Dispose();
}
}
else if (member.SchemaClassName == "User")
{
DataRow dr = table.NewRow();
dr["Machine"] = remMachine.Name.ToString();
dr["Group"] = "Administrators";
dr["User"] = member.Name.ToString();
table.Rows.Add(dr);
member.Dispose();
}
Reads to me as;
if (something)
membername.Dispose();
else
member.Dispose();
I'd expect something along these lines;
foreach (object groupMember in (IEnumerable)members)
{
using (var member = new DirectoryEntry(groupMember))
{
if (member.SchemaClassName == "Group")
..
You could gain some speed perhaps, if you had a thread for each result in there. Depends on how many results and how many cores your CPU got. A progressbar is often appreciated for longer-running tasks.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you for your answer.
I disable AppDomain.GetCurrentThreadId(), but I continue to get error.
Regards
|
|
|
|
|
So what you want? Be more specific..
|
|
|
|
|
Saridakis Manolis wrote: Thank you for your answer. I disable
AppDomain.GetCurrentThreadId(), but I continue to get error.
What answer? Is this from some other thread? If so, you should continue on that thread.
|
|
|
|
|
The AppDomain will not "hide" the exception as "Application.OnException" does. If you throw an exception, the thing will die.
You could wrap the dangerous part in a try..catch block, catching the exceptions that you expect.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Does anyone know why this code doenst work?(In a consonle Application)
it cant catch exceptions
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException);
throw new ArgumentException("for test");
}
static void MyException(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine(e.ExceptionObject);
}
}
Thanks
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
What do you mean "doesn't work"?
I just tried it and it does what I would expect.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Im wonderful it cant catgh any unhandled exceptions and clr shows unhandled exception windows when I see event viewer it shows these info about my program
Faulting application name: Mydynamic.exe, version: 1.0.0.0, time stamp: 0x507ac6d7
Faulting module name: KERNELBASE.dll, version: 6.1.7601.17514, time stamp: 0x4ce7bafa
Exception code: 0xe0434352
Fault offset: 0x0000b727
Faulting process id: 0x4b4
Faulting module path: F:\Windows\syswow64\KERNELBASE.dll
Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008
I dont have this problem in other programs(like WPF,Windows Forms or ASP.Net) it works for them and donest work for console applications
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
My complete test code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException);
throw new ArgumentException("for test");
}
static void MyException(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine("Exception Caught!");
Environment.Exit(0);
}
}
} My complete CMD output:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\griff>d:
D:\>cd \temp
D:\Temp>ca
Exception Caught!
D:\Temp>
What am I doing that differs from you?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
My code is the same with your code except (Environment.Exit(0); (I dont have this code) it works with this code but without it I got this message of e.ExceptionObject
System.ArgumentException: for test
at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17
and it shows this window
Windows can check online for a solution to the problems.
Check online for a solution and close the program
Close the program
Debug the problem
when I click on the "Debug the problem" item, visual sutdio Just In-Time debugger asks "Do you want to debug using the selected debugger?" after yes it goes to my code exception details are
System.ArgumentException was unhandled
Message=for test
Source=Mydynamic
StackTrace:
at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17
InnerException:
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
That is pretty much what I would expect. If you don't have the exception handler cause an program exit, then the system has no choice except to cause an abnormal termination - which is what your message shows.
Think about it: the exception is thrown from the Main method. The application cannot continue under any circumstances without restarting the whole program.
In Winforms et al., it is multithreaded, so a single thread can be terminated without necessarily killing the whole app - but your console app is a single thread. If it can't continue the only running thread, it can't continue the application.
In GUI apps, the Main function is executed in a thread, which fires off other threads to handle the UI for each form. They can be terminated without affecting the Main thread, since all it is doing is waiting for the others to die anyway!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
A question
I am making a new thread so my program have two threads (main thread) and worker thread then I am testing this code but the problem is same ?
could you explain it ?
Thanks
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hamid. wrote: I am making a new thread
Solution is simple. Don't let threads throw exceptions.
|
|
|
|
|
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyException);
throw new ArgumentException("for test");
}
static void MyException(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine("CAUGHT: " + e.ExceptionObject.ToString());
}
Works for me; displays the exception with the custom text in the console, and then switches to the debugger. What did you expect it to do, and what behaviour are you observing?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Its the result of event viewver
Faulting application name: Mydynamic.exe, version: 1.0.0.0, time stamp: 0x507ac6d7
Faulting module name: KERNELBASE.dll, version: 6.1.7601.17514, time stamp: 0x4ce7bafa
Exception code: 0xe0434352
Fault offset: 0x0000b727
Faulting process id: 0x4b4
Faulting application start time: 0x01cdaa154403b39d
Faulting application path: c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\bin\Debug\Mydynamic.exe
Faulting module path: F:\Windows\syswow64\KERNELBASE.dll
Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008
but I dont know why the path is c:\ all my programs are on f:\
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hamid. wrote: Its the result of event viewver
Doesn't contain much hints on what went wrong. I hope you're logging the full text of the exceptions?
Hamid. wrote: Faulting application path: c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\bin\Debug\Mydynamic.exe
Faulting module path: F:\Windows\syswow64\KERNELBASE.dll
Report Id: 81b9c3ff-1608-11e2-bc0d-005056c00008
but I dont know why the path is c:\ all my programs are on f:\
Looks like it's (also) being run from Visual Studio, debugging on it's C-drive.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Im using of visual studio 2010 SP1
I got this message of e.ExceptionObject
System.ArgumentException: for test
at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17
and it clr shows this window
Windows can check online for a solution to the problems.
Check online for a solution and close the program
Close the program
Debug the problem
when I click on the "Debug the problem" item, visual sutdio Just In-Time debugger asks
"Do you want to debug using the selected debugger?"
after yes it goes to my code
exception details are
System.ArgumentException was unhandled
Message=for test
Source=Mydynamic
StackTrace:
at ConsoleApplication1.Program.Main(String[] args) in c:\users\apple\documents\visual studio 2010\Projects\Mydynamic\Mydynamic\Program.cs:line 17
InnerException:
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
That seems to work as expected; the AppDomain-handler correctly gets the message and processes it. And no, it doesn't prevent the app from closing - you'll have to fix the exception.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Hello,
The problem is, when I run a method from other form (example: From form1 I call form2.mymethod) , it show me error in MessageBoxManager.cs
in:
hHook = SetWindowsHookEx(WH_CALLWNDPROCRET, hookProc, IntPtr.Zero, AppDomain.GetCurrentThreadId());
How can I solve this ?
Best regards
Manolis Saridakis
|
|
|
|
|
Saridakis Manolis wrote: How can I solve this ?
Disable the hook when debugging. It's not even related to the error you are reporting.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Why are you using AppDomain.GetCurrentThreadId() ?? That's been obsolate since .NET 2.0 because it doesn't return the correct ID in all cases.
Any why are you setting this hook at all??
|
|
|
|
|
Hi, i'm trying to get OpenCvSharp runing and i couldn't manage to make it work. Google tutorials haven't help, or i just can't get it right. Anyone that can help me installing and a basic tutorial?
I'm trying to make my program recognize a PS3 Eye (hopefull could choose in the differents resolutions settings), and show live video.
|
|
|
|
|
Daniel Heinsohn wrote: Google tutorials haven't help, or i just can't get it right. Anyone that can help me installing and a basic tutorial?
What makes you think my tutorials are better than those of Google? What does "couldn't manage to make it work" mean? Did you get an exception, some kind of error? Did the library not compile?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Those from google are probably the same ones you or anyone here post, i just can make them work i think. Whenever i want to run a code for recognizing camera, an error pops about the P/invoke. Give me 3 possible solutions, but non of them of my understanding.
OpenCV's DLL files exist in the same directory as the executable file....
Visual C++ Redistributable Package has been installed....
The target platform(x86/x64) of OpenCV's DLL files and OpenCvSharp is the same as your project's....
Maybe i got a wrong OpenCvSharp.dll
|
|
|
|