Initially on denial (^_^)/, I finally have time to investigate the issue. Tanmoy actually got it correctly. So I created a new GUI demo on how to correctly kill a particular Excel process.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Excel; using System.Diagnostics; namespace ThreadingGUI_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { ApplicationClass app = new ApplicationClass(); if (app == null) { MessageBox.Show("Unable to Open Excel"); } app.Visible = true; _Workbook wb = app.Workbooks.Add(XlWBATemplate.xlWBATWorksheet); this.listBox1.Items.Add(app.Hwnd); } private void button2_Click(object sender, EventArgs e) { if (this.listBox1.SelectedIndex >= 0) { Process[] procs = Process.GetProcessesByName("EXCEL"); int selectedExcel = (Int32)this.listBox1.SelectedItem; foreach (Process p in procs) { if (p.MainWindowHandle.ToInt32() == selectedExcel ) { p.Kill(); this.listBox1.Items.Remove(selectedExcel); } } } } } }
Thanks to Tanmoy (^_^)/
Download the Project here.
GD Star Rating
loading...
loading...
About Hardono
Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.
Incoming Search
asp.net, bugs, ms excel