示例#1
0
        private void OnElapsedTime(object source, ElapsedEventArgs e)
        {
            TraceService("in on elapsed time" + DateTime.Now);

            try
            {
                var repo = new ScrurRepository();
                List <ScreenNailerItem> list = repo.GetScreenNails(false);

                TraceService("Number of items to process " + list.Count);

                foreach (ScreenNailerItem item in list)
                {
                    using (System.Diagnostics.Process process = new System.Diagnostics.Process())
                    {
                        string scrid = item.ScreenNailerId.ToString();
                        string refid = item.ReferenceId.ToString(); //"5";
                        string url   = item.Url;                    //"http://www.news.com";

                        //string ar = scrid + " " + refid + " " + url;
                        string args = " " + ConfigurationManager.AppSettings["rootlocation"] + "scrur.js " + url + " " + ConfigurationManager.AppSettings["rootlocationimages"] + refid + ".png";

                        TraceService("Current screen nailer item being processed " + args);

                        //process.StartInfo = new System.Diagnostics.ProcessStartInfo(ConfigurationManager.AppSettings["scrurnailerconsolelocation"],args); //c:\windows\system32\cmd.exe

                        //process.StartInfo.CreateNoWindow = false;
                        //process.StartInfo.ErrorDialog = true;
                        //process.StartInfo.RedirectStandardError = true;
                        //process.StartInfo.RedirectStandardInput = true;
                        //process.StartInfo.RedirectStandardOutput = true;
                        //process.StartInfo.UseShellExecute = true;
                        //process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;

                        //process.Start();

                        process.StartInfo.UseShellExecute        = false;
                        process.StartInfo.RedirectStandardOutput = true;
                        process.StartInfo.CreateNoWindow         = false;
                        process.StartInfo.FileName  = ConfigurationManager.AppSettings["scrurnailerconsolelocation"];
                        process.StartInfo.Arguments = args; // +" " + imagefilename;

                        process.Start();
                        //string output = process.StandardOutput.ReadToEnd();
                        process.WaitForExit();

                        //// do some other things while you wait...
                        //System.Threading.Thread.Sleep(10000); // simulate doing other things...
                        //process.StandardInput.WriteLine("exit"); // tell console to exit
                        //if (!process.HasExited)
                        //{
                        //    process.WaitForExit(120000); // give 2 minutes for process to finish
                        //    if (!process.HasExited)
                        //    {
                        //        process.Kill(); // took too long, kill it off
                        //    }
                        //}

                        //Set the nail as processed
                        repo.SetScreenNailerProcessed(item.ScreenNailerId);
                    }
                }
                //TraceService("Another entry at " + DateTime.Now);
            }
            catch (System.Exception ex)
            {
                TraceService(ex.Message + " " + ex.StackTrace);
            }
        }