dispose

“Object can be disposed of more than once” error

安稳与你 提交于 2019-12-17 23:15:05
问题 When I run code analysis on the following chunk of code I get this message: Object 'stream' can be disposed more than once in method 'upload.Page_Load(object, EventArgs)'. To avoid generating a System.ObjectDisposedException you should not call Dispose more than one time on an object. using(var stream = File.Open(newFilename, FileMode.CreateNew)) using(var reader = new BinaryReader(file.InputStream)) using(var writer = new BinaryWriter(stream)) { var chunk = new byte[ChunkSize]; Int32 count;

Timer not disposed when form is

匆匆过客 提交于 2019-12-17 19:49:15
问题 I am trying to understand why a Windows.Forms.Timer is not disposed when the form that created it is. I have this simple form: public partial class Form1 : Form { private System.Windows.Forms.Timer timer; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer = new Timer(); timer.Interval = 1000; timer.Tick += new EventHandler(OnTimer); timer.Enabled = true; } private void OnTimer(Object source, EventArgs e) { Debug.WriteLine("OnTimer entered");

Should I dispose a Mutex?

微笑、不失礼 提交于 2019-12-17 19:33:47
问题 I'm working on 2 Windows Services that have a common database which I want to lock (cross-process) with a system Mutex. Now I'm wondering whether it's ok to just call WaitOne() and ReleaseMutex() in a try-finally block or should I also dispose the Mutex (e.g. in a using block). If so I guess I should always catch the AbandonedMutexException on the WaitOne() method or am I wrong here? 回答1: A mutex is a Windows kernel object (here wrapped in a .NET object). As such, it is an unmanaged resource

Dispose JFrame from another class

 ̄綄美尐妖づ 提交于 2019-12-17 17:15:33
问题 How can I dispose JFrame from another class? My code is listed below. I use Netbeans generate form for generate window. And I want dispose using another class(name is needDispose). public class needDispose { /** *Call for dispose frame */ public static void disposeMyFrame(){ myEasyFrame.getMainFrame.dispose(); // DOESNT WORK } } NETBEANS GENERATE (important method is getMainFrame() ) import javax.swing.JFrame; public class myEasyFrame extends javax.swing.JFrame { /* * Get frame */ public

Why would I need to call dispose on ASP.NET Controls?

天大地大妈咪最大 提交于 2019-12-17 16:45:18
问题 I'm doing some ASP.NET development in VS and have just found an interesting little code suggestion (I think they come from coderush but I could be wrong). Whenever I'm creating controls it tells me that I should be using a "using" statement for them. I'm a bit confused as to what is going on here though. with the using my code looks something like: using (HtmlTableRow tableRow = new HtmlTableRow()) { tableRow.Attributes.Add("class", isOddRow ? "OddRow" : "EvenRow"); listingTable.Rows.Add

Why would I need to call dispose on ASP.NET Controls?

流过昼夜 提交于 2019-12-17 16:45:01
问题 I'm doing some ASP.NET development in VS and have just found an interesting little code suggestion (I think they come from coderush but I could be wrong). Whenever I'm creating controls it tells me that I should be using a "using" statement for them. I'm a bit confused as to what is going on here though. with the using my code looks something like: using (HtmlTableRow tableRow = new HtmlTableRow()) { tableRow.Attributes.Add("class", isOddRow ? "OddRow" : "EvenRow"); listingTable.Rows.Add

How to abort socket's BeginReceive()?

↘锁芯ラ 提交于 2019-12-17 15:46:32
问题 Naturally, BeginReceive() will never end if there's no data. MSDN suggests that calling Close() would abort BeginReceive() . However, calling Close() on the socket also performs a Dispose() on it, as figured out in this great ansewr, and consequently EndReceive() would throw an exception because the object is already disposed (and it does!). How should I proceed? 回答1: It seems like this is by (the very dumb) design. You must have this exception thrown and caught in your code. MSDN looks

Adding / Removing components on the fly

被刻印的时光 ゝ 提交于 2019-12-17 11:03:13
问题 I need to be able to add & remove Angular components on the fly. To do so, I'm using loadIntoLocation and dispose methods, like it: Adding a component (from a layout manager): this.m_loader.loadIntoLocation(MyComponent, this.m_element, 'content').then(_componentRef => { // Create the window and set its title: var component: MyComponent = (_componentRef.instance); component.ref = _componentRef; // init the component content }); Removing a component (from the component): this.ref.dispose(); It

Adding / Removing components on the fly

爱⌒轻易说出口 提交于 2019-12-17 11:01:51
问题 I need to be able to add & remove Angular components on the fly. To do so, I'm using loadIntoLocation and dispose methods, like it: Adding a component (from a layout manager): this.m_loader.loadIntoLocation(MyComponent, this.m_element, 'content').then(_componentRef => { // Create the window and set its title: var component: MyComponent = (_componentRef.instance); component.ref = _componentRef; // init the component content }); Removing a component (from the component): this.ref.dispose(); It

Adding / Removing components on the fly

て烟熏妆下的殇ゞ 提交于 2019-12-17 11:01:46
问题 I need to be able to add & remove Angular components on the fly. To do so, I'm using loadIntoLocation and dispose methods, like it: Adding a component (from a layout manager): this.m_loader.loadIntoLocation(MyComponent, this.m_element, 'content').then(_componentRef => { // Create the window and set its title: var component: MyComponent = (_componentRef.instance); component.ref = _componentRef; // init the component content }); Removing a component (from the component): this.ref.dispose(); It