Questions tagged [unmanagedresources]

67 questions
8
votes
7 answers

Do we have Unmanaged resources in C#?

I had a discussion with my friend about managed and unmanaged resources in c#. According to my friend: 1.a) Every object in C# is managed and there is nothing like unmanaged object or resource when we code in C#. Unmanaged resource concept comes…
Vinod Menezes
  • 355
  • 2
  • 10
8
votes
2 answers

Should Marshal.FreeHGlobal be placed in a finally block to ensure resources are disposed?

I have the following block of code: IntPtr unmanagedPointer = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, unmanagedPointer, buffer.Length); SomeCommandThatCanThrowAnException(); Marshal.FreeHGlobal(unmanagedPointer); Should the…
vicsz
  • 9,552
  • 16
  • 69
  • 101
7
votes
3 answers

How to dispose unmanaged resource manually?

I am using some unmanaged code like- [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int Description, int ReservedValue); //Creating a function that uses the API function... public static bool…
Arpit Khandelwal
  • 1,743
  • 3
  • 23
  • 34
7
votes
0 answers

Application exiting with an exit code of -1073740771

I have a WPF application, which sometimes is exiting with an exit code of -1073740771. The issue is not occurring in any pattern and it's varying from system to system. In some system the issue is occurring for less that 10% of the total cases and…
Pratik Bhattacharya
  • 3,596
  • 2
  • 32
  • 60
6
votes
4 answers

Need to implement a finalizer on a class that uses TcpClient?

I have a class (say MyClass) that uses (has as a private field) a TcpClient object. MyClass implements IDisposable calling TcpClient.Close in the Dispose method. My question is should MyClass also implement a finalizer to call Dispose(bool…
CSharpeProgrammer
5
votes
4 answers

How can I add jars from more than one unmanaged directory in an SBT .scala project configuration

I'm trying to get SBT to build a project that could have more than one unmanaged directory. If I had a single directory, I could easily do it like this: unmanagedBase := file( "custom-libs" ).getAbsoluteFile But since I have two directories with…
Maurício Linhares
  • 39,901
  • 14
  • 121
  • 158
4
votes
6 answers

Is there a guarantee on the order in which the Dispose() method is called when using multiple using statements for the same scope in C#?

using (Stuff1 stf1 = new Stuff1(...)) // Allocation of stf1 using (Stuff2 stf2 = new Stuff2(...)) // Allocation of stf2 { try { // ... do stuff with stf1 and stf2 here ... } catch (Stuff1Exception ex1) { // ... …
user972301
  • 137
  • 8
4
votes
1 answer

How to exclude unmanaged resources from Compile scope only (not from Test)

In one of my sub projects, I am trying to exclude *.conf and *.groovy files from my list of unmanaged resources: excludeFilter in Compile in unmanagedResources := "*.conf" || "*.groovy" Now, this works but has the unintended effect of removing the…
HenryM
  • 41
  • 3
3
votes
3 answers

unmanaged dll code

I am having a C# (.NET 3.5, VS2005 Professional) application that uses unmanaged 32bit library written in C/C++. API that I use is like this: void * Initialize(int x); voic GetData(void *); And this works when I run it on Windows XP 32bit, but on…
Mita
  • 243
  • 5
  • 11
3
votes
4 answers

Managed vs Unmanaged Resources in .NET. What's the difference?

I was reading Wrox's Professional C# 4 and .NET 4 chapter on "Memory Management and Pointers", specifically about how Garbage Collection works in .NET. It said the reason that "the garbage collector does not know how to free unmanaged resources…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
3
votes
1 answer

How can I tell if a resource is unmanaged?

I'm Using Visual Studio 2017 to write C# apps. I strive to dispose of all objects I instantiate by utilizing the "using" statement. Visual Studio warns me if I instantiate an object NOT based on a type that is implicitly convertible to…
user2414250
3
votes
1 answer

Does matter COM object not assigned to var is not released?

Will be all unmanaged COM objects released in case if I use code like this var worksheet = new Application().Workbooks.Add().Worksheets.Add(); Marshal.ReleaseComObject(worksheet); instead of code like this var excel = new Application(); var…
Yarl
  • 728
  • 1
  • 7
  • 26
3
votes
2 answers

Unmanaged resources and Dispose()

I was reading some articles about Dispose() method and found that unmanaged resources should be freed explicitly from Dispose() method (or finalize() method) and the article says file handles and database connection objects are examples of unmanaged…
Aparan
  • 1,263
  • 3
  • 12
  • 17
3
votes
1 answer

Deploying unmanaged DLLs to output directory

I am trying to organize my VS 2010 solution. One area that is holding me back is the use of Unmanaged DLLs. I can’t add them as References because the DLLs are unmanaged. The previous approach was to xcopy the DLLs from a “lib” folder during the…
3
votes
3 answers

Unmanaged Resources, IDisposable and Custom Types

yet another topic on the subject as I got tired of reading countless topics to find an answer to my questions :) Lets say we have the following class: public class MyClass { private const string conString = "connection string"; private int…
1
2 3 4 5