dispose

Do I need to Dispose a SemaphoreSlim

非 Y 不嫁゛ 提交于 2019-12-10 00:44:44
问题 According to the documentation: "a SemaphoreSlim doesn't use a Windows kernel semaphore". Are there any special resources used by the SemaphoreSlim which make it important to call Dispose when the SemaphoreSlim will no longer be used? 回答1: Yes. It may use a ManualResetEvent that uses a SafeWaitHandle which is a SafeHandle and it has an unmanaged handle. You can see it in the reference source here. SafeHandle is finalizable so if you don't dispose of it (by disposing of the SemaphoreSlim ) it

Do I need to Close and/or Dispose callback channels acquired through OperationContext.Current.GetCallbackChannel?

女生的网名这么多〃 提交于 2019-12-09 14:38:37
问题 I'm using OperationContext.Current.GetCallbackChannel to get a channel to the client that called a WCF service operation. Do I need to worry about closing / disposing these callback channels or is this taken care of by the framework? 回答1: Well, I just tried it myself and it turns out that if you Close & Dispose the callback channel (after casting to IClientChannel) the entire Service channel becomes useless and when called throws a ProtocolException saying: "This channel can no longer be used

Does the .dispose() method do anything at all?

跟風遠走 提交于 2019-12-09 06:12:45
问题 I was experimenting with ways to get rid of some memory leaks within my application the other day when I realized that I know virtually nothing about cleaning up my resources. I did some research, and hoped that just calling the .dispose() would solve all of my problems. We have a table in our database that contains about 65,000 records. Obviously when I fill my dataset from the data adapter, the memory usage can get pretty high. When I called the dispose method on the dataset, I was

How to wait for a single event in C#, with timeout and cancellation

青春壹個敷衍的年華 提交于 2019-12-09 05:08:59
问题 So my requirement is to have my function wait for the first instance an event Action<T> coming from another class and another thread, and handle it on my thread, allowing the wait to be interrupted by either timeout or CancellationToken . I want to create a generic function I can reuse. I managed to create a couple options that do (I think) what I need, but both seem more complicated than I'd imagine it should have to be. Usage Just to be clear, a sample use of this function would look like

Can a CryptoStream be returned and still have everything dispose correctly?

陌路散爱 提交于 2019-12-09 03:11:21
问题 If I have a CryptoStream that I want to pass back to the user, the naïve approach would be public Stream GetDecryptedFileStream(string inputFile, byte[] key, byte[] iv) { var fsCrypt = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read); var rmCrypto = new RijndaelManaged(); var transform = rmCrypto.CreateDecryptor(key, iv); var cs = new CryptoStream(fsCrypt, transform, CryptoStreamMode.Read); return cs; } I know that when I dispose the CryptoStream the underlying

Dispose SmtpClient in SendComplete?

两盒软妹~` 提交于 2019-12-09 03:01:19
问题 When I use SmtpClient's SendAsync to send email, how do I dispose the smtpclient instance correctly? Let's say: MailMessage mail = new System.Net.Mail.MailMessage() { Body = MailBody.ToString(), IsBodyHtml = true, From = new MailAddress(FromEmail, FromEmailTitle), Subject = MailSubject }; mail.To.Add(new MailAddress(i.Email, "")); SmtpClient sc = new SmtpClient(SmtpServerAddress); //Add SendAsyncCallback to SendCompleted sc.SendCompleted += new SendCompletedEventHandler(SendAsyncCallback); /

Implementing the View.IOnTouchListener interface

心已入冬 提交于 2019-12-08 17:30:32
问题 In Xamarin, I have coded a class that implements the View.IOnTouchListener interface. Here is my code: public class OnTouchListener : View.IOnTouchListener { public bool OnTouch (View v, MotionEvent e) { return true; } void IDisposable.Dispose () { throw new NotImplementedException (); } IntPtr Android.Runtime.IJavaObject.Handle { get { throw new NotImplementedException (); } } } What values do I need for the IDisposable.Dispose and Android.Runtime.IJavaObject.Handle code items, rather than

Dispose of SWT shell when cursor moves out of it

南笙酒味 提交于 2019-12-08 11:35:01
问题 I'm implementing a custom preview/tooltip for an Eclipse plug-in. It did it using a Shell in SWT, removing all its trimmings and placing a text box inside it. It looks great. However now I need to dispose of the shell when the cursor moves out of the shell window and I ran into some issues: Does it make sense to attach a mousemoveListener to the shell? First I was doing this but then I realized that this listener only captures mouse move Events which occur inside the shell. How will I capture

Do I need to dispose of dynamically-created controls before exiting a form?

社会主义新天地 提交于 2019-12-08 09:56:43
问题 I've created a new instance of my options form with the using directive, so it is disposed of automatically when I'm finished with it. Do I need to dispose of the dynamically-created controls on the form before closing it, or will they be automatically disposed of when I call this.Close() ? 回答1: Generally no, all controls are dynamically created. Usually in the InitializeComponent() method, it isn't fundamentally different when the code appears somewhere else. Dynamically removing controls is

Visual Studio .NET error: Form does not contain Dispose(bool) method

依然范特西╮ 提交于 2019-12-08 08:30:11
问题 Occasionally Visual Studio (2005, 2008, 2010) will lose its mind, and get confused by a WinForm: SplashForm.cs: public partial class SplashForm : Form { ... SplashForm.Designer.cs: partial class SplashForm { ... protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } ... It will complain: protected override void Dispose(bool disposing) 'Dispose(bool)' has no suitable method to override base.Dispose(disposing