Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6893235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:38:01+00:00 2026-05-27T06:38:01+00:00

When a field is used for creating another field, and then disposed – I

  • 0

When a field is used for creating another field, and then disposed – I see two options. First:

Image image = Image.FromFile(path);
Bitmap bitmap = (Bitmap)image.GetThumbnailImage(32, 32, null, new IntPtr());
image.Dispose();//not needed anymore.

//use bitmap

bitmap.Dispose();

Second:

using (Image image = Image.FromFile(path))
{
    using (Bitmap bitmap = (Bitmap)image.GetThumbnailImage(32, 32, null, new IntPtr()))
    {
        //use bitmap
    }
}

The logical one would be the first (because the Image isn’t needed when the Bitmap is used), but using statements are generally preferable over Dispose.

Is there a third way – to terminate the first using inside the second one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:38:02+00:00Added an answer on May 27, 2026 at 6:38 am

    Yes, there is: Put the code to produce the thumbnail image into a method:

    Bitmap GetThumbnail(string path)
    {
        using (Image image = Image.FromFile(path))
        {
            return (Bitmap)image.GetThumbnailImage(32, 32, null, new IntPtr());
        }
    }
    
    // ...
    
    using (Bitmap bitmap = GetThumbnail(path))
    {
        //use bitmap
    }
    

    Please note:
    I agree with Oded’s comments. I would use this code not because it disposes image first, but because it is more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in creating tinyint field in MySQL database using Hibernate. I used
In ASP.NET 2, I've used Field Validators, and RequiredField validators, but I'm unsure of
I used a new Date() object to fill a field in a MySQL DB,
I used HTTPService for reading xml, but I want only a particular xml field
Could someone tell me how the field Task Group is used in standard SharePoint
I have generally always used some sort of Hungarian Notation for my field names
I am creating a program for my exam in programming on first semester of
Here's my scenario: I'm creating a password change page. the real field that holds
I am creating an ASCII output file contain some information and two of my
I'm creating a web page to select some options from a CSV file: CSV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.