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

  • SEARCH
  • Home
  • 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 6153011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:01:17+00:00 2026-05-23T20:01:17+00:00

I am using an external API to interface to a FireWire Camera. The API

  • 0

I am using an external API to interface to a FireWire Camera. The API is propably written in C++ but thankfully it brings its own .NET wrapper DLLs. The API requires the following procedure:

ApiResource.Init();
// ... use the ressource here ...
ApiResource.CloseAll();
ApiResource.Release();

Because I need some specific handling code I decided to write a wrapper class for this. I need to keep the ressources open while my Form is open because of Event Handlers, etc. So I thought to make the wrapper easier to use I’d make it a singleton implementing IDisposable so I can wrap it in a using statement. The reason I want a Singleton is to have a controlled and limited way of calling the required API functions:

class Wrapper : IDisposable {
  private Wrapper _instance;
  public Wrapper Instance
  {
    get
    {
      if(_instance == null)
        _instance = new Wrapper();
      return _instance;
    }
  }

  private Wrapper ()
  {
    ApiResource.Init();
    _disposed = false;
  }

  // Finalizer is here just in case someone
  // forgets to call Dispose()
  ~Wrapper() {
    Dispose(false);
  }

  private bool _disposed;

  public void Dispose()
  {
    Dispose(true);

    GC.SuppressFinalize(this);
  }

  protected virtual void Dispose(bool disposing)
  {
    if(!_disposed)
    {
       if(disposing)
       {
       }
       ApiResource.CloseAll();
       ApiResource.Release();
       _instance = null;
       log("Wrapper disposed.");
       _disposed = true;
    }
  }
}

The way I want to use it is this:

using(Wrapper.Instance) {
  Application.Run(new Form());
}

I’m quite new to C# so I am very unsure of a couple of things:

  1. Will Dispose() always be called in the above using(Singleton.Instance) { ... }? My logging suggests “yes”, but I’m unsure…
  2. Is it safe to wrap Application.Run(...) with a using-statement?
  • 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-23T20:01:18+00:00Added an answer on May 23, 2026 at 8:01 pm

    The answer to both of your questions is yes:

    • Dispose() will always be called when the using block ends, unless Wrapper.Instance was null when the block began.

    • It is perfectly safe to wrap the call to Run() in a using block.

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

Sidebar

Related Questions

I have a program that uses an external API which uses its own state.
I have a need to create a transactional process using an external API that
How do i pass three arguments using external interface in flash to a java
I want to make some API calls to a server using HttpURLConnection . But
I have a ASP.Net C# application that needs to connect to an external API
I'm using a cross-domain Ajax request to an external API. Every so often it
Of the FCL classes (or even using an external API) is there a utility
I make a request to an external API using GET method. For some reasons,
My project makes various calls to external API's using Python's urllib2.urlopen . I'm using
A blog post - http://petewarden.typepad.com/searchbrowser/2011/05/using-hadoop-with-external-api-calls.html - suggests calling external systems (querying the twitter API,

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.