472,789 Members | 1,331 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

Disposable & 3rd Party Lib & GUI

Hi,

I'm wrapping a 3rd party .NET 2.0 CF library which mandates Dispose be
called.

So, I mandate Dispose be called on my library...I follow the Disposable
pattern described on MSDN...and I Dispose of the wrapped 3rd party
library in there.

My library is meant to be used in Forms.

My question is simply -- what's the proper way to shut down a form?
There is:

~ destructor

<form>_Closing( )

<form>_Closed( )

should I call one of the following, and if so...where...->

Application.Exit( );

this.Close( );

Where should I issue the Dispose( ) on my library?

Jan 16 '07 #1
3 1591

davis wrote:
Hi,

I'm wrapping a 3rd party .NET 2.0 CF library which mandates Dispose be
called.

So, I mandate Dispose be called on my library...I follow the Disposable
pattern described on MSDN...and I Dispose of the wrapped 3rd party
library in there.

My library is meant to be used in Forms.

My question is simply -- what's the proper way to shut down a form?
There is:

~ destructor

<form>_Closing( )

<form>_Closed( )

should I call one of the following, and if so...where...->

Application.Exit( );

this.Close( );

Where should I issue the Dispose( ) on my library?
I see you suggest Application.Exit in your list. Does it mean that your
form is only closed when the application shuts down? In this case, I
don't think you even need to call Dispose(). Resources will all be
freed when the application is shut down.

Jan 16 '07 #2
Where should I issue the Dispose( ) on my library?

I see you suggest Application.Exit in your list. Does it mean that your
form is only closed when the application shuts down? In this case, I
don't think you even need to call Dispose(). Resources will all be
freed when the application is shut down.
Hi Virgil, this is not the case...especially in the compact framework
(at least what I have found). Getting an application to really exit
seems a tricky endeavor especially when you are using unmanaged
resources.

My library uses System.IO.Stream as the means to communicate directly
with the underlying hardware that is exposed from the 3rd party
library.

The 3rd party library mandates Dispose be called only once and when the
application exits. If it is called twice it throws
ObjectDisposedException.

If it is not called and the process unexpectedly terminates, then the
internal state machine of the hardware gets all screwed up and may
require a hard reset of the device. This really stinks, but this is
the way it is as I have no insight into the 3rd party code. So I have
to protect for all measures where the application terminates via any
kind of exception and make sure this doesn't happen.

This is why I implemented the Disposable pattern as per the example
here http://msdn2.microsoft.com/en-us/lib...isposable.aspx

On the main UI form, there is a Window Style -MinimizeBox property.
In CF, when set to True, the app does not terminate when the X button
is pressed, but it hides it. If set to false, it changes the X to an
Ok icon...and when pressed it is supposed to terminate.

Thus, in Form_Closing( ) I call my libraries Dispose( ), which in turn
calls the 3rd Party Library Dispose( ) -- and hope it works...but when
I run the remote process viewer on the device, I see the .exe is still
running, and not sure why...which led me to ask my original question --
what is the recommended practice here?

Jan 16 '07 #3

davis wrote:
Where should I issue the Dispose( ) on my library?
I see you suggest Application.Exit in your list. Does it mean that your
form is only closed when the application shuts down? In this case, I
don't think you even need to call Dispose(). Resources will all be
freed when the application is shut down.

Hi Virgil, this is not the case...especially in the compact framework
(at least what I have found). Getting an application to really exit
seems a tricky endeavor especially when you are using unmanaged
resources.

My library uses System.IO.Stream as the means to communicate directly
with the underlying hardware that is exposed from the 3rd party
library.

The 3rd party library mandates Dispose be called only once and when the
application exits. If it is called twice it throws
ObjectDisposedException.

If it is not called and the process unexpectedly terminates, then the
internal state machine of the hardware gets all screwed up and may
require a hard reset of the device. This really stinks, but this is
the way it is as I have no insight into the 3rd party code. So I have
to protect for all measures where the application terminates via any
kind of exception and make sure this doesn't happen.

This is why I implemented the Disposable pattern as per the example
here http://msdn2.microsoft.com/en-us/lib...isposable.aspx

On the main UI form, there is a Window Style -MinimizeBox property.
In CF, when set to True, the app does not terminate when the X button
is pressed, but it hides it. If set to false, it changes the X to an
Ok icon...and when pressed it is supposed to terminate.

Thus, in Form_Closing( ) I call my libraries Dispose( ), which in turn
calls the 3rd Party Library Dispose( ) -- and hope it works...but when
I run the remote process viewer on the device, I see the .exe is still
running, and not sure why...which led me to ask my original question --
what is the recommended practice here?
Well then, I'm clueless (I'm kinda new to C# and .NET). Maybe that your
3rd party library didn't implement the finalizer of their IDisposable
correctly (because it is supposed to call Dispose(false), and if it
did, well, as I wrote in my other message, you wouldn't even have to
call Dispose()).

Maybe The problem isn't with the Dispose(), but with some invalid stuff
you perform with the hardware that messes things up? Or with the order
in which stuff is disposed in your app?

Anyway, to answer you question, personnally, I put application's
initialization code in Program.Main(), before the "Application.Run(new
MainForm());" line, an the finalization code after that line. I
wouldn't put application level finalization in Form_Closing(), it
doesn't seem proper to me. There may be cases where this isn't called
(wild guess here, I'm not sure).

Jan 16 '07 #4

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

Similar topics

25
by: rbt | last post by:
Are there any plans in the near future to support PDF files in Python as thoroughly and completely as Perl does? http://cpan.uwinnipeg.ca/search?query=pdf&mode=dist I love Python's clean...
7
by: header_question | last post by:
Is it best to place all #include files in one header file seperate from all the other files in a project? What is the logic that determines the order of the #include files, does it depend on the...
4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&amp;" when it gets used as a querystring in the url EG: ...
17
by: Bruno | last post by:
I have a feature that is hosted on a different domain from the primary one in a frame, and need to retain values in a cookie. example: A web page at one.com contains a frame which has a page...
9
by: James Stroud | last post by:
Hello All, I have been trying to make an https client with python, but it seems that, to do this, one needs to have the socket module compiled with ssl. This is not the default. So I have a...
0
by: bboldi | last post by:
I created a disposable email service (and a public login database) http://www.dontreg.com - PHP MYSQL - to help people fight against spam , and i am searching for testers... so please if you have...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
42
by: coder_lol | last post by:
Thanks everyone again for contributing to helping me clear C++ confusions. I did some serious reading on copy constructors and assignments and I think I've got a good handle on the memory stuff. ...
4
by: robtyketto | last post by:
Greetings, I’m writing a research report on justifying disposable prototypes. The problem being there is a wealth of material regarding failures in the IT press and some of these put partial...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

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.