Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

using using

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Martijn Mulder - 11 Sep 2007 09:14 GMT
When I want to invoke Dispose() automatically on an object, I can use

using(object)
{
 //do something with object
}

and after the closing brace the object is Disposed(). But what get
disposed when I use code like this

override protected void OnPaint(PaintEventArgs e)
{
 using(e.Graphics.Clip=GetMyCustomRegion())
 {
  e.Graphics.DrawImage(bitmap,0,0);
 }
}

Is the Region object returned by GetMyCustomRegion() succesfully
Disposed()? How does it influence the Clip-property of the Graphics object?

Also, can I nest 'using' statement like this:

override protected void OnPaint(PaintEventArgs e)
{
 using(e.Graphics.Clip=GetMyCustomRegion())
 using(Bitmap bitmap=new Bitmap(34,55))
 {
  e.Graphics.DrawImage(bitmap,0,0);
 }
}

Do both the implicit Region object and the Bitmap object get Disposed()?
Alex Meleta - 11 Sep 2007 09:34 GMT
Hi Martijn,

MM> using(e.Graphics.Clip=GetMyCustomRegion())
MM> Is the Region object returned by GetMyCustomRegion() succesfully Disposed()?

Yes, why not, reference is the same, it's kind of
   using (Region tempRegion = (e.Graphics.Clip = <new Region()>))
   {
       e.Graphics.DrawImage(null, 0, 0);
   }

MM> using(e.Graphics.Clip=GetMyCustomRegion())
MM> using(Bitmap bitmap=new Bitmap(34,55))
First for the bitmap, then for the region.

http://msdn2.microsoft.com/en-us/library/yh598w02(VS.80).aspx

Regards, Alex
[TechBlog] http://devkids.blogspot.com

MM> When I want to invoke Dispose() automatically on an object, I can
MM> use
MM>
MM> using(object)
MM> {
MM> //do something with object
MM> }
MM> and after the closing brace the object is Disposed(). But what get
MM> disposed when I use code like this
MM>
MM> override protected void OnPaint(PaintEventArgs e)
MM> {
MM> using(e.Graphics.Clip=GetMyCustomRegion())
MM> {
MM> e.Graphics.DrawImage(bitmap,0,0);
MM> }
MM> }
MM> Is the Region object returned by GetMyCustomRegion() succesfully
MM> Disposed()? How does it influence the Clip-property of the Graphics
MM> object?
MM>
MM> Also, can I nest 'using' statement like this:
MM>
MM> override protected void OnPaint(PaintEventArgs e)
MM> {
MM> using(e.Graphics.Clip=GetMyCustomRegion())
MM> using(Bitmap bitmap=new Bitmap(34,55))
MM> {
MM> e.Graphics.DrawImage(bitmap,0,0);
MM> }
MM> }
MM> Do both the implicit Region object and the Bitmap object get
MM> Disposed()?
MM>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.