0

The following code is running fine on my computer but it hangs on office computer

        ProcessStartInfo info = new ProcessStartInfo();
        info.Verb = "print";
        info.FileName = @"c:\temp\" + filename;
        info.CreateNoWindow = true;
        info.WindowStyle = ProcessWindowStyle.Hidden;

        Process p = new Process();
        p.StartInfo = info;
        p.Start();

        p.WaitForInputIdle();
        System.Threading.Thread.Sleep(3000);
        if (false == p.CloseMainWindow())
            p.Kill();

Please help

slugster
  • 49,403
  • 14
  • 95
  • 145
Hasan Zubairi
  • 1,037
  • 4
  • 23
  • 57
  • "Doesn't work" - how? Is the target file present on the office computer? Is there even a C:\temp folder? Does the user you are running as have rights to the file in C:\temp? – slugster Jul 04 '14 at 01:18
  • Folder is created and the file is also present but it hangs when it tries to run this code. – Hasan Zubairi Jul 04 '14 at 01:21
  • The process hangs? You've not got a printer settings dialog that isn't being shown? – slugster Jul 04 '14 at 01:24
  • yes but it hangs with windows busy icon and nothing happens the screen dulls and have to shut down the application. – Hasan Zubairi Jul 04 '14 at 01:25
  • Remove the "CreateNoWindow=true" line, and try it again, it may help you debug the problem. – dodald Jul 04 '14 at 01:40
  • The error it is giving is system.InvalidOperationException Process has exited so the requested information is not available – Hasan Zubairi Jul 04 '14 at 04:16

1 Answers1

0

Some computers are slower then others so the process is exiting before it is finished. Increasing the thread sleep time fixed the problem.

Hasan Zubairi
  • 1,037
  • 4
  • 23
  • 57