|
The project I am working on has a memory leak and will throw OutOfMemory exception when left running long enough. I believe the source of this problem is an object which multiple instances are created and never properly freed. After I am done with the object I would like to manually call Dispose().
The object is defined as such and is contained within a struct implementing IDisposable.
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct CamAcquisition : IDisposable
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 82944)]
public ushort[] frameData;
...
}
I do not know how to properly implement Dispose() to free this object.
How can I manually free an instance of this object?
|
|
|
|
|
Hi,
whatever is marked [MarshalAs(UnmanagedType.ByValArray, SizeConst = 82944)] inside a struct, becomes an integral part of that struct, and cannot be deleted/removed/disposed at all. The whole attribute is intended to mimic an unmanaged array inside a struct, that is why its size has to be constant and known at build time. The entire struct is a value type, so it gets allocated on the stack and lives as long as your surrounding method is alive.
Furthermore, I'm not sure how you are using your struct and why you would want to make it implement IDisposable. It would take more explaining I guess. The only use I see for struct.Dispose() is when it also allocates and holds on to unmanaged resources.
|
|
|
|
|
hi all,
I have used win xp an this code runnig normally but when I started to use win7 it is not working what is it my problem
thanks..
foreach (ServiceController service in services)
{
if (service.ServiceName == "SistemServisleri")
{
string argu = @"/C sc delete SistemServisleri";
System.Diagnostics.Process.Start(@"c:\Windows\system32\cmd.exe", argu);// for win7 I used it but not working
System.Diagnostics.Process.Start("cmd", argu);// for winxp I used it and working
}
}
|
|
|
|
|
Have you debugged it? Does the service exist? What do you mean it doesn't work? Does it not run? Does it through an exception?
Please format any code you post using the pre tags, i.e. the "code block" link in the edit menu.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I want to delete this servis with this code but it can't be deleted
|
|
|
|
|
Is it a UAC (user account control) problem? Even if you are a member of the admin group, you must run that program "as administrator" explicitly.
|
|
|
|
|
for administrator I use
System.Diagnostics.Process.Start(@"c:\Windows\system32\cmd.exe", argu);
|
|
|
|
|
YOur code has to run as an administrator. Under Vista and 7, even an admin account doesn't run as an admin account until the privilege requires it and you get the UAC box. To get around that UAC box, you have to create a manifest file in your project that specifies the app needs admin level permissions to run.
Here's[^] a quick'n'dirty on what you need to do.
|
|
|
|
|
Have u tried it to using WMI?
|
|
|
|
|
The code needs to be running as an admin regardless of how you do it.
|
|
|
|
|
Hi.
In my project have 3 module. 1 and 2 nd module writen in c++ and 3th module - Application module written in C#.
Every module different parts of projects.
My first module have like that class :
class __declspec(dllexport) MyClass1
{
public :
int n;
MySimple1()
{
n=0;
}
~MySimple1()
{
}
int Plus(int a,int b)
{
return n=(a+b);
}
};
In my second module have like that class.
And this class use 1 th class.
class __declspec(dllexport) MyClass2
{
public :
MySimple2(MyClass1 a)
{
}
~MySimple2()
{
}
...
};
Can i use MyClass1 fields (i know how to use methods) in my C# app?
In my C# app , how i can send MyClass1 like parameter to 2nd class ?
How i can use like that in my C# app ?
public MyClass1 my1=new MyClass1();
int n=my1.Plus(10,12);
MySimple2(my1);
Thanks.
We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
You would need to use pinvoke and create interop to access the unmanaged classes.
This might help http://www.pinvoke.net/[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for reply.
I know how to use class methods with pinvoke. But i need use that class (NO METHOD) ?
Any ideas?
thanks.
We are haven't bug,just temporarily undecided problems.
|
|
|
|
|
I found answer here[^]
I hope that will help you
|
|
|
|
|
Runtime Call Wrapepers are for COM. This is just a normal C++ class exposed in the export table. In C++ calling methods on a class use a calling convention called ThisCall. With ThisCall the "this" pointer gets passed into the method via the ECX register and everything else is the same as STD call. .Net supports this. You can specify this calling convention in the DllImport attribute. How the constructor and destructor get called is something else. When you specify ThisCall in the DllImport attribute the first parameter of the method must be a pointer to "This". The names are going to be mangled in the export table. Use a program like dependency walker to see what they are.
Here is a good post I found on this site.
How to Marshal a C++ Class[^]
modified on Friday, October 1, 2010 2:38 PM
|
|
|
|
|
Create a wrapper class in a CLI project (C++.NET) and you should be able to access the C++ class from the .NET class. The advantage of this is that you keep your C++ project as is and you can debug both heaps easily. In this mode the unmanaged and managed heaps run within the same process without marshaling. I hope this helps.
|
|
|
|
|
Hi, I'm using an application that generates groups and assign users in active directory to manage a series of folders. i don't know much about AD and so I would like to know if someone can tell me the road. The point is that I have to manage permissions for read-only, full control ... do not know if I have to give to the groups or folders, plus I have no idea how to make it... would appreciate some help, thanks ....
|
|
|
|
|
allstarmisho wrote: I have no idea how to make it
Start by researching, then find some code-snippets and try to combine what you have. The Scripting Center[^] on MSDN has some nice examples on manipulating the AD.
Good luck
I are Troll
|
|
|
|
|
Hi,
One of the column type in my datagridview is datagridviewImage column. it has "recyclebin" image. If I'm try to edit the row, recyclebin image will be changed to edit image.
The problem is, how to know which row is having edit image and which row is having recyclebin image.
I used the below statement to compare, but its not working.
if (dgvIdentifiers["Recycle", e.RowIndex].Value == Resources.recycle)
Note:recycle is the image, resided in Resources
|
|
|
|
|
There are two ways that I have managed to do this.
1) Have a hidden DataGridViewTextBoxColumn , I call it imageHint where I store a string either the path of the image or something like, in your example, "recycle" or "edit". Then any time an image is assigned, assign the appropriate string to imageHint
2) The same principle but use the Tag property of the cell. If you are not familiar with Tag , search MSDN there are loads of examples of how to use it.
Hope this helps.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I used Tag property of cell. It helped me. Thanks alot..
|
|
|
|
|
Good to know!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
Am need to overwrite the Assemblyinfo.cs file.
ex: [assembly: AssemblyVersion("1.0.0.0")]
needs to be upadted to [assembly: AssemblyVersion("4.0.0.0")]
Instead of manuallly updating i need to update it from code.
The below code reads the version number.
But i need to update it in Assmeblyinfo.cs file,can you help me to update thro code?
using system.reflection;
Version v1 = new Version("4.0.0.0");
Console.WriteLine(" New Version {0}.", v1);
Thanks,
Arul
|
|
|
|
|
Hi Arul,
Reflection does not seem to be the best way to do this. I suggest that you should search all AssemblyInfo.cs files in a specified folder (using DirectoryInfo-class). Open each file (with a StreamReader) and read the file content. Then use a regular expression (Regex-namespace) to find the "AssemblyVersion"-string and replace the version with '4.0.0.0' or whatever number you want to set. Then write the content to the file (to overwrite) by using a StreamWriter.
After that you can build your assembly with the new version number.
Let me know if you need more details on the point where you stuck.
Regards
Sebastian
|
|
|
|
|
Hi Sebastian,
Thanks for your faster response. I tried using DirectorInfo-class. But it says duplicate assembly info files.It would be great if you could chip out with code too.
Also can this be done using cmd prompt.?
Thanks,
Arul
|
|
|
|