Hi,
Used the Microsoft example quoted in the comments to make a simple application with three buttons, start excel, disconnect from excel and exit the form.
Did not need to disconnect, closing Excel does not close the application.
Something you are doing with the handle is causing the issue and as I am not sure what you are trying to achieve I cannot say why - rather I know why it is closing the form app just not sure what you are trying to achieve.
namespace WinFormsApp1
{
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
public partial class Form1 : Form
{
Excel.Application excelApp;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Close();
}
private void button2_Click(object sender, EventArgs e)
{
excelApp = new Excel.Application();
excelApp.Visible = true;
excelApp.WindowState = XlWindowState.xlMaximized;
}
private void button3_Click(object sender, EventArgs e)
{
while (Marshal.ReleaseComObject(excelApp) != 0)
;
}
}
}