dispose

What's the recommended way to deal with leaked IAsyncDisposable instances?

夙愿已清 提交于 2021-02-18 22:31:31
问题 I've been familiarizing myself with some of the things (that are planned to be) added in C# 8 & .NET Core 3.0, and am unsure on the correct way to implement IAsyncDisposable (at time of writing, this link has literally no guidance). In particular, it is unclear to me what to do in the case when an instance isn't explicitly disposed - that is, it isn't wrapped in an async using(...) and .DisposeAsync() isn't explicitly called. My first thought was to do that same thing I'd do when implementing

Does C# automatically “dispose” IDisposable objects when they fall out of scope?

℡╲_俬逩灬. 提交于 2021-02-16 20:07:24
问题 I am writing an ASP.NET Web API. As part of this, I have a class that I found out, during testing, needs to implement IDisposable to ensure managed resources are freed. So, I implemented IDisposable in my class, and put the code necessary to free the resources in the Dispose() method. There are many places in my code (hundreds) where I instantiate this object, and in the same line call a method on the new instance. I only need the instance to call the single method. Here's an example: //

Does C# automatically “dispose” IDisposable objects when they fall out of scope?

不羁的心 提交于 2021-02-16 20:04:34
问题 I am writing an ASP.NET Web API. As part of this, I have a class that I found out, during testing, needs to implement IDisposable to ensure managed resources are freed. So, I implemented IDisposable in my class, and put the code necessary to free the resources in the Dispose() method. There are many places in my code (hundreds) where I instantiate this object, and in the same line call a method on the new instance. I only need the instance to call the single method. Here's an example: //

Does SslStream.Dispose dispose its inner stream

匆匆过客 提交于 2021-02-05 12:11:28
问题 I use NetworkStream with sockets in an SslStream socket server as follows: stream = new NetworkStream(socket, true); sslStream = new SslStream(stream, false); My question is, if when I call sslStream.Dispose() , will the SslStream dispose/close its inner stream and its socket too? Or do I need to explicitly close all three resources with sslStream.Close() , stream.Close() and socket.Close() ? 回答1: If possible, you should use C#'s using construct to dispose the stream 'automatically' after use

Does SslStream.Dispose dispose its inner stream

谁说我不能喝 提交于 2021-02-05 12:09:29
问题 I use NetworkStream with sockets in an SslStream socket server as follows: stream = new NetworkStream(socket, true); sslStream = new SslStream(stream, false); My question is, if when I call sslStream.Dispose() , will the SslStream dispose/close its inner stream and its socket too? Or do I need to explicitly close all three resources with sslStream.Close() , stream.Close() and socket.Close() ? 回答1: If possible, you should use C#'s using construct to dispose the stream 'automatically' after use

Does SslStream.Dispose dispose its inner stream

天大地大妈咪最大 提交于 2021-02-05 12:05:12
问题 I use NetworkStream with sockets in an SslStream socket server as follows: stream = new NetworkStream(socket, true); sslStream = new SslStream(stream, false); My question is, if when I call sslStream.Dispose() , will the SslStream dispose/close its inner stream and its socket too? Or do I need to explicitly close all three resources with sslStream.Close() , stream.Close() and socket.Close() ? 回答1: If possible, you should use C#'s using construct to dispose the stream 'automatically' after use

Close window - but don't stop program - JAVA

纵饮孤独 提交于 2021-02-05 08:09:15
问题 In my program it opens a window if an action is happened. After I have filled out information in this window, and entered a button, the window dispose(). The window is picked up in a program outside my main program, but when I close this window, my main program stops. How can I prevent this from happening? Thanks for your help! 回答1: You can set the defalaultCloseOperation property of the second frame to DO_NOTHING_ON_CLOSE or DISPOSE_ON_CLOSE Don't even use two frames. Use a modal JDialog

Why is there no Dispose method to override in .Net Core?

徘徊边缘 提交于 2021-01-05 07:40:20
问题 I am trying to dispose of my DbContext in my GenericRep from my Generic Service. My generic repo is implementing the pattern described here: https://docs.microsoft.com/en-us/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application I have set up the first part in my repo: public class GenericRepository<T> : IGenericRepository<T>, IDisposable where T: BaseEntity { protected readonly

How and when to dispose my objects?

霸气de小男生 提交于 2020-12-27 03:18:50
问题 In my backend service I use unit of work pattern. I was wondering if I'm missing something related to disposing objects. First, this is the code I have so far, which works. The service just calls a request handler: [GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler))] public class CustomerService : ICustomerService { public void AddCustomer(AddCustomerRequest request) { ObjectFactory.GetInstance<AddCustomerRequestHandler>().Execute(request); } } The request handler looks like:

How and when to dispose my objects?

大城市里の小女人 提交于 2020-12-27 03:17:37
问题 In my backend service I use unit of work pattern. I was wondering if I'm missing something related to disposing objects. First, this is the code I have so far, which works. The service just calls a request handler: [GlobalExceptionHandlerBehaviour(typeof(GlobalExceptionHandler))] public class CustomerService : ICustomerService { public void AddCustomer(AddCustomerRequest request) { ObjectFactory.GetInstance<AddCustomerRequestHandler>().Execute(request); } } The request handler looks like: