Thank you for your answer, gile.
This property changing doesn't help if
accoreconsole.exe already is launched (my code is located in the .net extension of AutoCAD). Also I've tried to use
FreeConsole() winapi function:
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool FreeConsole();
At this case console window will be closed (instead of hiding) successfully, then code of static constructor of my class and of
Initialize() method will work successfully too, but right after it the
accoreconsole process will be finished (even without calling the
Terminate() and
ProcessExit):
using System;
using System.ServiceModel;
using cad = Autodesk.AutoCAD.ApplicationServices.Core.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using System.Runtime.InteropServices;
using System.Diagnostics;
[assembly
: ExtensionApplication
(typeof(Bushman
.CAD.Services.ExtensionApplication))]
namespace Bushman.CAD.Services {
public class ExtensionApplication : IExtensionApplication {
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool FreeConsole();
static ServiceHost host = null;
static ExtensionApplication() {
try {
FreeConsole();
host.Open();
AppDomain.CurrentDomain.ProcessExit += ProcessExit;
}
catch (System.Exception ex) {
Document doc = cad.DocumentManager.MdiActiveDocument;
if (null != doc) doc.Editor.WriteMessage(ex.Message);
}
}
private static void ProcessExit(object sender, EventArgs e) {
if (null != host) host.Close();
}
public void Initialize() {
string status = null == host ? "null" : host.State.ToString();
Document doc = cad.DocumentManager.MdiActiveDocument;
if (null != doc) doc.Editor.WriteMessage("\nHost status: {0}.\n", status);
}
public void Terminate() {
// Nothing is here.
}
}
}