The program exits suddenly when I launch another process

4


My program exists suddenly and I can't find the reason but I know which parts of the code cause this problem. I will try to explain what happens...

First of all, I use following namespaces in my windows form in addition to the common ones:

using System.Diagnostics;
using System.IO;
using System.Data.OleDb;

I have a custom function which retrieves the current auto increment row ID by finding the maximum ID and incrementing it by one:

void getCurrentQuestionNo()
{
    //calculate current questionNo based on DB Info
    classDataLayer DL = new classDataLayer();
    OleDbCommand cmd = new OleDbCommand();
    cmd.CommandText = "SELECT MAX([questionID]) FROM questions";
    DataSet ds = DL.select(cmd);
    questionNo = Convert.ToInt32(ds.Tables[0].Rows[0][0]) + 1;
}

This function is launched inside form_load function to set a global variable called questionNo for later use.

Also I have the following code to open an instance of microsoft word application. This code is placed inside the click event of a button:

try
{
    //copy an instance of empty question template to Temp folder
    File.Copy(@"Templates\EmptyQuestion.docx", @"Temp\TempQuestion.docx", true);
    //launch ms-word to open the document
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "WINWORD.EXE";
    startInfo.Arguments = @"Temp\TempQuestion.docx";
    Process.Start(startInfo);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

THE PROBLEM:
Either of codes for retrieving last questionNo and opening word document works fine separately. I mean when I call getCurrentQuestionNo() inside form_load it works and there is no problem. When I disable getCurrentQuestionNo() function inside form_load, the code for launching word process works fine.
However, when I call getCurrentQuestionNo() inside form_load and then click the button to launch word process, still everything works but suddenly after a few seconds whole the program exits without any messages and the word remains running. It's like I hit Stop button from Visual Studio IDE.
What can be wrong?

This is shown in output window:
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
The program '[5032] test.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[5032] test.vshost.exe: Managed (v4.0.30319)' has exited with code -2147483645 (0x80000003).

I tested a lot of cases, any use of oleDB along with the use of process causes the same problem. I reduced my codes as follows:
Code for retrieving last auto increment ID:

OleDbConnection con1 = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=db.accdb");
OleDbCommand cmd1 = new OleDbCommand("SELECT MAX([questionID]) FROM questions", con1);
con1.Open();
txtID.Text = cmd1.ExecuteScalar().ToString();
con1.Close();

and code for launching a process:

Process p = new Process();
p.StartInfo.FileName = "notepad.EXE";
p.Start();

I put them inside the click events of two separate buttons. Again each button works correctly when they clicked solely but clicking button1 then button2 crashes the program!!!
I am really confused... :(
The interesting thing is that sometimes the program does not exit by itself and everything continues working, but in such cases "vshost.exe has stopped working" dialogue box appears when I close the program normally. Problem details shows that ntdll.dll is the fault module and sometimes clr.dll. I also get this: Fault Module Name: StackHash_4d02

c#
winforms
process
asked on Stack Overflow Oct 3, 2013 by Sys Soft • edited Oct 4, 2013 by John Saunders

1 Answer

0

I very much doubt your problem is corrupted DLLs. I'd say it's more likely a missing DLL, or a 32/64-bit mismatch. Download a copy of Dependency Walker and run it against your app. If you're missing DLLs or the DLLs Windows finds don't match the architecture, it will tell you. Just make sure and download the correct version for your app (32 vs 64 bit).

answered on Stack Overflow Oct 4, 2013 by Carey Gregory

User contributions licensed under CC BY-SA 3.0