public static void Run()
        {
            //ExStart:1
            string SourceDir = RunExamples.GetDataDir_DWGDrawings();
            string OutputDir = RunExamples.GetDataDir_Output();

            using (Image cadDrawing = Image.Load(SourceDir + "Drawing11.dwg"))
            {
                var rasterizationOptions = new CadRasterizationOptions();

                rasterizationOptions.PageWidth  = cadDrawing.Size.Width;
                rasterizationOptions.PageHeight = cadDrawing.Size.Height;

                using (var its = new InterruptionTokenSource())
                {
                    PdfOptions CADf = new PdfOptions();
                    CADf.VectorRasterizationOptions = rasterizationOptions;
                    CADf.InterruptionToken          = its.Token;

                    var exportTask = Task.Factory.StartNew(() =>
                    {
                        cadDrawing.Save(OutputDir + "PutTimeoutOnSave_out.pdf", CADf);
                    });

                    Thread.Sleep(10000);
                    its.Interrupt();

                    exportTask.Wait();
                }
            }
            //ExEnd:1
            Console.WriteLine("PutTimeoutOnSave executed successfully");
        }
        //ExStart:SupportForInterrupt
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_PresentationProperties();

            Action <IInterruptionToken> action = (IInterruptionToken token) =>
            {
                LoadOptions options = new LoadOptions {
                    InterruptionToken = token
                };
                using (Presentation presentation = new Presentation(dataDir + "pres.pptx", options))
                {
                    presentation.Save(dataDir + "pres.ppt", SaveFormat.Ppt);
                }
            };

            InterruptionTokenSource tokenSource = new InterruptionTokenSource();

            Run(action, tokenSource.Token); // run action in a separate thread
            Thread.Sleep(10000);            // timeout
            tokenSource.Interrupt();        // stop conversion
        }
示例#3
0
        //ExStart:SupportForInterrupt
        public static void Run()
        {
            string dataDir = RunExamples.GetDataDir_PresentationProperties();
            Action <InterruptionToken> action = (InterruptionToken token) =>
            {
                using (Presentation pres = new Presentation("pres.pptx", new LoadOptions {
                    InterruptionToken = token
                }))
                {
                    pres.Slides[0].GetThumbnail(new Size(960, 720));
                    pres.Save("pres.ppt", SaveFormat.Ppt);
                }
            };

            InterruptionTokenSource tokenSource = new InterruptionTokenSource();

            Run(action, tokenSource.Token); // run action in a separate thread from the pool

            Thread.Sleep(5000);             // some work

            tokenSource.Interrupt();        // we don't need the result of an interruptable action
        }