I have this App that uses the Webbrowser control to do automated browsing. I need to come up with a way to automatically close the browser (dispose), then create another instance that actually works.
Here's some of the code that I have so far.
this.webBrowser2 = new System.Windows.Forms.WebBrowser();
this.webBrowser2.Dock = System.Win...
This might seem like a noddy question, but I was looking at this because I heard someone claiming that you must call Close() on a FileStream, even if it is in a using block (and they have code where Close() is being called right at the end of the block).
I know that Close() is meant to call Dispose(), but I thought I'd look deeper since...
Folks,
My question is: Can this be done better? and if so, How? Any ideas?
We need to start a captive IE session from within an "invisible" C# .NET 3.5 application, and quit both the IE session and the "parent" application after processing a certain request.
I've been mucking around with this problem for the last week or so... and thi...
I'm having difficulty with C#'s 'Dispose' pattern. I have 3 classes at play here: A management class, a form, and a data-storage class.
The management class may (if it needs to) use the form to prompt the user for input. The form loads data from a file, which the user can then modify. As it is closed, the form must save this data back. ...
I have this object PreloadClient which implements IDisposable, I want to dispose it, but after the asynchronous methods finish their call... which is not happening
private void Preload(SlideHandler slide)
{
using(PreloadClient client = new PreloadClient())
{
client.PreloadCompleted +...
The scenario I have, is in the Execute method of a SPJobDefinition I want to go through every SPSite in the web application. So I have the following code:
foreach (SPSite site in this.WebApplication.Sites)
{
...
}
Question is, do I need to dispose of each site? The rule I normally go by is dispose or put inside a using only if I new...
I'm profiling out unit & integration tests, and I find the a lot of the time is spent on the finalizer of NHibernate.Transaction.AdoTransaction - this means it is not getting disposed properly.
I am not using AdoTransaction directly in the code, so it's probably used by some other object inside NHibernate. Any idea what I'm forgetting t...
The SPDisposeCheck utility alerted me to an impproperly disposed SPWeb.Add call. As you can see below, the typical using(SPWeb NewWeb = webs.add(siteUrl ....) method would not work because of the RunWithElevatedPrivileges would make the return newWeb out of context.
By looking at the newWeb = webs.Add() line below, can anyone suggest a...
I've had a suspicion that a database connection used in one of our applications is not always closed. I went to see the code and I've found a class DataProvider that has SqlConnection object. The connection is opened in the constructor of this class and closed in it's Dispose method (don't judge that, i know keeping an open connection is...
Recently, I was researching some tricky bugs about object not disposed.
I found some pattern in code. It is reported that some m_foo is not disposed, while it seems all instances of SomeClass has been disposed.
public class SomeClass: IDisposable
{
void Dispose()
{
if (m_foo != null)
{
m_foo.Dispose();
...
I was wondering if there was some sort of cheat sheet for which objects go well with the using statement... SQLConnection, MemoryStream, etc.
Taking it one step further, it would be great to even show the other "pieces of the puzzle", like how you should actually call connection.Close() before the closing using statement bracket.
Anyth...
I am getting this warning from FxCop:
"'RestartForm' contains field 'RestartForm.done' that is of IDisposable type: 'ManualResetEvent'. Change the Dispose method on 'RestartForm' to call Dispose or Close on this field."
Ok, I understand what this means and why this is what needs to be done... Except System.Windows.Forms.Form doesn'...
How can I make sure in the following code snippet that IDataReader is disposed of if ExecuteReader throws an exception?
using (IDataReader rdr = cmd.ExecuteReader())
{
// use it
}
It makes sense to me that the using syntatic sugar does not call Dispose (since there is no instance to call it on). However, how can I be sure that the...
I have a WinForms TabControl that I am dynamically adding TabPages to at runtime. Each TabPage contains a WebBrowser control. I also have the ability to remove the TabPages at runtime.
Should I bother Dispose()ing the TabPage and/or WebBrowser controls?
It seems to me I should at least Dispose() the WebBrowser control since it is a bit...
Reading about the Dispose pattern, I see the documentation repeatedly refer to "cleaning up managed and unmanaged code". And in the canonical implementation of the Dispose method, I see specific flows (depending on whether disposing is true or false) dedicated to the cleanup of managed objects versus unmanaged objects.
But am I, the lo...
Hi all,
I have noticed interesting behaviour in our .NET WinForms app. We have an mdi form that has many mdi children added. These child forms listen to a "broadcast" event which is in essence a call to refresh itsself. The event is declared in a base class and the listening events added in the child forms.
I've noticed that even when ...
Let's say I have a class Collection which holds a list of Items.
public class Collection
{
private List<Item> MyList;
//...
}
I have several instances of this Collection class which all have different MyLists but share some Items.
For example: There are 10 Items, Collection1 references Items 1-4, Collection2 has Items 2-8 and ...
Hi all,
I have a windows form that contains many controls e.g timers, gridviews, and binding sources etc, and all of these expose a dispose function. Do I have to call their dispose function in this
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
compon...
I recently saw some VB .NET code as follows:
Dim service = ...
Try
...
service.Close()
Finally
service = Nothing
End Try
Does assigning Nothing to service do anything? If it is a garbage collection issue, I am assuming that when "service" went out of scope the referenced object would be garbage collected and the dispose metho...
In one of the WCF tutorials, I saw the followign sample code:
Dim service as ...(a WCF service )
try
..
service.close()
catch ex as Exception()
...
service.abort()
end try
Is this the correct way to ensure that resources (i.e. connections) are released even under error conditions?
Thanks for the answers guys! I up...