473,586 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using(OpenFileD ialog dlg ...) dispose issue

Hi all,

In this code snip

try
{
using(OpenFileD ialog dlg = new OpenFileDialog( ))
{
//do something
}
}
catch
{
//do someting
}

if CLR throw FileOntFoundExc eption in try block, Will dlg call
dlg.Dispose() finally?

thanks.
Nov 17 '05 #1
1 4940
It should get disposed as indicated in the C# spec.
http://msdn.microsoft.com/library/de...pspec_8_13.asp

The following code...

using (OpenFileDialog dlg = new OpenFileDialog( ))
{
//do something
}

....should get expanded to something like this...

OpenFileDialog dlg = new OpenFileDialog( );
try
{
//do something
}
finally
{
if (dlg != null)
{
((IDisposable)d lg).Dispose();
}
}

--
Tim Wilson
..Net Compact Framework MVP

"Austin Jan" <au********@gma il.com> wrote in message
news:Op******** ******@TK2MSFTN GP09.phx.gbl...
Hi all,

In this code snip

try
{
using(OpenFileD ialog dlg = new OpenFileDialog( ))
{
//do something
}
}
catch
{
//do someting
}

if CLR throw FileOntFoundExc eption in try block, Will dlg call
dlg.Dispose() finally?

thanks.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2385
by: Dev | last post by:
Friends, I want display the directory name(is not file names)using openFileDialog controls.Is it possible? If so how do to this? If anyone knows....Please help me... Thanks, Dev
8
10313
by: ..:: Kevin ::.. | last post by:
If I load a PictureBox image from an embedded resource within my application it works fine but if I load the same image from a file using OpenFileDialog (as an ImageStream or using the file name) the background color is not masked out. Any ideas?
8
7371
by: dvp10 | last post by:
Hi, i want open an .exe file using OpenFileDialog() in C# The code i ve used is - Stream strm; StreamReader reader; try { strm = OpenFileDialog1.OpenFile(); reader = new StreamReader(strm);
1
2675
by: DKn | last post by:
Hi, How to get the Files from Remote system by using OpenFileDialog control in C#.Net windows application? Actually i am trying to do Software upgradation for a remote system by using Win32_Product. For this i need to give the Patch location by using OpenFileDialog Control.. how to do this... Thanks in advance..
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.