I have developed a C# winforms app with RealDWG SDK. When I close my form I get the "App has stopped working" error below.
I've added in some Dispose methods to see if that was the issue, but I still get the error.
I added a dispose method to my HostApplication class and I called my Winform dispose method.
I thought that the error was caused by unfinished RealDWG business at the Form Closing event.
I am using RealDWG 2013, Visual Studio 2010 SP1, Windows 7 64-bit.
I also have AutoCAD 2012 and 2013 installed.
I know that AutoCAD and RealDWG both use acdb19.dll.
My app contains 6 classes with around 1000 lines of code on each class, so to paste in my code would be impossible. Here is my code structure.
I start by implementing a HostApplicationService Class (MyHost.cs)
Then I call my Windows Form. (MainForm.cs)
From my form I collect object data from a SqlDatabase.
Once the data is aquired, I send the data to a Class that handles my AutoCAD classes. (AutoCAD.cs)
In this class I create my RealDWG Database.
Next I pass the database to various IDisposable classes that perform AutoCAD actions.
I.E, CreateTitleBlock() CreateLayers(), DrawShape(); etc..
Everything works great, except when I go to close the app, I get the error.
I dispose everything I can think of right before exiting.
I've tried
this.Close();
Application.Exit();
Any ideas on how to dispose the app or close it cleanly?
Thanks,
Eric
Here is the error....
Problem signature:
Problem Event Name: APPCRASH
Application Name: LongBayRD.exe
Application Version: 1.0.0.0
Application Timestamp: 519fa185
Fault Module Name: acdb19.dll
Fault Module Version: 19.0.55.0
Fault Module Timestamp: 4f309c70
Exception Code: c0000005
Exception Offset: 0000000000058166
Solved! Go to Solution.
Solved by DiningPhilosopher. Go to Solution.
I really appreciate the response, I figured it out.
// app form closing event
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
MyHost.WorkingDatabase = null;
MyHost.Current.Dispose();
Application.Exit();
}
// constructor for HostApplicationServices class
public MyHost()
{
RuntimeSystem.Initialize(this, 1033);
}
// dispose method for HostApplicationServices class
void IDisposable.Dispose()
{
this.Dispose();
RuntimeSystem.Terminate(); // added this to fix it
}
Simple RealDWG 101 Rules.
I guess I failed to mention that this is my first RealDWG project.
See attached for the complete MyHost class.
There may be better ways to shut down the RuntimeSystem but for now this is the technique I plan to use.
@EriCSharp wrote:
// dispose method for HostApplicationServices class
void IDisposable.Dispose()
{
this.Dispose();
RuntimeSystem.Terminate(); // added this to fix it
}
You're deriving from a class that already implements IDisposable, and provides a virtual overridable Dispose( bool ) method that you can override to get control when the instance is disposed. You shouldn't implement IDisposable again on your class, you should instead override the Dispose( bool ) method of the base class (DisposableWrapper), and do your cleanup in that, and then call base.Dispose( bool ) to let the base class do its thing.
Yes, I see ..... thanks DiningPhilosopher
protected override void Dispose(bool value)
{
RuntimeSystem.Terminate();
}