コード例 #1
0
        public void Start()
        {
            //create the thread with its ThreadStart method
            this.StatusThread = new Thread(() =>
            {
                try
                {
                    this.Popup = new PleaseWaitWindow();
                    this.Popup.setText(Msg);
                    this.Popup.Show();
                    this.Popup.Closed += (lsender, le) =>
                    {
                        //when the window closes, close the thread invoking the shutdown of the dispatcher
                        this.Popup.Dispatcher.InvokeShutdown();
                        this.Popup        = null;
                        this.StatusThread = null;
                    };

                    //this call is needed so the thread remains open until the dispatcher is closed
                    System.Windows.Threading.Dispatcher.Run();
                }
                catch (Exception ex)
                {
                    ExceptionMessageBox exp = new ExceptionMessageBox(ex, "Error in Waiting Dialog");
                }
            });

            //run the thread in STA mode to make it work correctly
            this.StatusThread.SetApartmentState(ApartmentState.STA);
            this.StatusThread.Priority = ThreadPriority.Normal;
            this.StatusThread.Start();
        }
コード例 #2
0
 public static void Close()
 {
     if (wnd == null)
     {
         return;
     }
     wnd.Close();
     wnd = null;
 }
コード例 #3
0
 public static void Show(string message)
 {
     if (wnd == null)
     {
         wnd = new PleaseWaitWindow {
             DataContext = message
         };
     }
     wnd.DataContext = message;
     wnd.Show();
 }
コード例 #4
0
        private void ConvertToStream(string fileUrl)
        {
            try
            {
                Thread waitThread = new Thread(() =>
                {
                    PleaseWaitWindow wait = new PleaseWaitWindow();

                    wait.ShowDialog();
                    // wait.LoadingAdorner.IsAdornerVisible = true;
                    wait.Close();
                });
                waitThread.SetApartmentState(ApartmentState.STA);
                waitThread.Start();
            }

            catch
            {
            }

            System.Threading.Thread.Sleep(2000);

            try
            {
                //  ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);

                HttpWebRequest  request  = (HttpWebRequest)WebRequest.Create(fileUrl);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();



                var    theStream = new object();
                string fileName  = AppDomain.CurrentDomain.BaseDirectory + "Printings" + @"\toPrint.pdf";


                using (var stream = File.Create(fileName))
                {
                    File.SetAttributes(fileName, FileAttributes.Normal);
                    response.GetResponseStream().CopyTo(stream);
                }

                iTextSharp.text.pdf.PdfReader pdfReader = new iTextSharp.text.pdf.PdfReader(fileName);
                int numberOfPages = pdfReader.NumberOfPages;

                if (GlobalCounters.numberOfCurrentPrintings + numberOfPages <= Convert.ToInt32("6"))
                {
                    try
                    {
                        // this.log.Info("Invoking Action: ViewPrintRequested " + numberOfPages.ToString() + " pages.");
                    }
                    catch
                    { }

                    System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
                    info.UseShellExecute = true;
                    info.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                    info.Verb            = "print";
                    info.FileName        = fileName;
                    info.CreateNoWindow  = true;


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

                    p.WaitForInputIdle();
                    p.CloseMainWindow();

                    /*  if (numberOfPages < Int32.Parse(this.numberOfAvailabelPagesToPrint))
                     * {
                     *    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(numberOfPages));
                     * }
                     * else
                     * {
                     *    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10));
                     * }*/
                    System.Threading.Thread.Sleep(TimeSpan.FromSeconds(6));

                    if (false == p.CloseMainWindow())
                    {
                        try
                        {
                            p.Kill();
                        }
                        catch { }
                    }
                    else
                    {
                        try
                        {
                            p.Kill();
                        }
                        catch { }
                    }

                    try
                    {
                        //  this.sender.SendAction("Printed " + numberOfPages + " pages.");
                    }
                    catch { }
                    GlobalCounters.numberOfCurrentPrintings += numberOfPages;
                }

                else
                {
                    System.Windows.MessageBox.Show("Unfortunately, you can not print so many pages! Please press OK to continue.");
                }
            }
            catch
            {
            }
            finally
            {
                //response.Close();
            }
        }