• <menu id="w2i4a"></menu>
  • logo VectorDraw Developer Framework使用教程

    文檔首頁(yè)>>VectorDraw Developer Framework使用教程>>VDF常見(jiàn)問(wèn)題整理(十八):關(guān)于多線程的打印問(wèn)題

    VDF常見(jiàn)問(wèn)題整理(十八):關(guān)于多線程的打印問(wèn)題


        VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫(kù)。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。   

    VectorDraw Developer Framework試用版下載


    問(wèn):

        有關(guān)于多線程的打印問(wèn)題,應(yīng)該如何解決?

    答:

        已改進(jìn)了順序調(diào)用vddocument不同實(shí)例的方法以在多線程項(xiàng)目中工作,一個(gè)線程用于每個(gè)不同的vdDocument。

    Example:
    using System;
    using System.Threading;
    using VectorDraw.Professional.Components;
    using VectorDraw.Professional.vdObjects;
    using System.Windows.Forms;
    using VectorDraw.Generics;namespace MultiPrint
    {
        class Program
        {
            const string ExportExtension = ".pdf";
            //const string ExportExtension = ".svg";
            //const string ExportExtension = ".jpg";
            //const string ExportExtension = ".emf";
            //const string ExportExtension = ".bmp";
            //const string ExportExtension = ".png";
            //const string ExportExtension = ".HPG";        //const string ExportExtension = ".dxf";
            public static bool IsPrintExportFormat
            {
                get
                {
                    return
                       (string.Compare(ExportExtension, "", true) == 0
                       || string.Compare(ExportExtension, ".jpg", true) == 0
                       || string.Compare(ExportExtension, ".pdf", true) == 0
                       || string.Compare(ExportExtension, ".svg", true) == 0
                       || string.Compare(ExportExtension, ".emf", true) == 0
                       || string.Compare(ExportExtension, ".HPG", true) == 0
                       || string.Compare(ExportExtension, ".png", true) == 0
                       || string.Compare(ExportExtension, ".bmp", true) == 0
                       );
                }
            }
            [STAThread]
            static void Main(string[] args)
            {
                Console.BufferWidth = 180;            FolderBrowserDialog folderbrowser = new FolderBrowserDialog();
                folderbrowser.RootFolder = Environment.SpecialFolder.Desktop;
                folderbrowser.SelectedPath = Environment.CurrentDirectory;
                DialogResult res = folderbrowser.ShowDialog();            if (res != DialogResult.OK) return;
                string argument = folderbrowser.SelectedPath + @"\";
                string folder = System.IO.Path.GetDirectoryName(argument);
                Environment.CurrentDirectory = folder;
                if (folder == null || folder == string.Empty || !System.IO.Directory.Exists(folder)) throw new Exception("Pass an existing folder as argument.");
                string[] files = System.IO.Directory.GetFiles(folder, "*.*", System.IO.SearchOption.TopDirectoryOnly);            vdArray<string> filenames = new vdArray<string>();
                foreach (string filename in files)
                {
                    if (filename.EndsWith(".vdcl", StringComparison.InvariantCultureIgnoreCase)
                         || filename.EndsWith(".vdml", StringComparison.InvariantCultureIgnoreCase)
                         || filename.EndsWith(".dwg", StringComparison.InvariantCultureIgnoreCase)
                         || filename.EndsWith(".dxf", StringComparison.InvariantCultureIgnoreCase)
                        )
                    {
                        filenames.AddItem(filename);
                    }
                }
                string message = "SelectedFiles :";
                foreach (string item in filenames)
                {
                    message += string.Format("\n{0}", item);
                }
                message += string.Format("\n\n Continue Exporting to {0} ?", ExportExtension);
                res = MessageBox.Show(message, "Selected Files", MessageBoxButtons.YesNo);
                if (res == DialogResult.No) return;
                int i = 0;            foreach (string item in filenames)
                {
                    BeginNewPrintJob(item, i); i++;
                } 
            }
            static void BeginNewPrintJob(string filename, int jobid)
            {
                DocumentJob job = new DocumentJob(jobid);            Thread thread = new Thread(new ParameterizedThreadStart(job.PrintFile));
                thread.Name = "PrintJob : " + filename;
                thread.SetApartmentState(ApartmentState.MTA);
                thread.Start(filename);
            }
            class DocumentJob
            {
                int lineNo = 0;
                public DocumentJob(int jobId)
                {
                    lineNo = jobId;
                }
                public void PrintFile(object Params)
                {
                    string fname = Params as string;
                    PrintMessage(string.Format("{0,-40} ", System.IO.Path.GetFileName(fname)) + "Start");                vdDocumentComponent DocComponent = new vdDocumentComponent();
                    vdDocument document = DocComponent.Document;
                    document.FileName = fname;
                    document.OnPrompt += new vdDocument.PromptEventHandler(document_OnPrompt);
                    document.OnProgress += new VectorDraw.Professional.Utilities.ProgressEventHandler(document_OnProgress);
                    document.GenericError += new vdDocument.GenericErrorEventHandler(document_GenericError);
                    document.OnLoadUnknownFileName += new vdDocument.LoadUnknownFileName(document_OnLoadUnknownFileName);
                    document.OnIsValidOpenFormat += new vdDocument.IsValidOpenFormatEventHandler(document_OnIsValidOpenFormat);
                    document.OnSaveUnknownFileName += new vdDocument.SaveUnknownFileName(document_OnSaveUnknownFileName);
                    document.OnGetSaveFileFilterFormat += new vdDocument.GetSaveFileFilterFormatEventHandler(document_OnGetSaveFileFilterFormat);
                    bool success = document.Open(fname);
                    if (success)
                    {
                        success = false;
                        if (IsPrintExportFormat)
                        {
                            vdPrint printer = document.Model.Printer;
                            printer.PrinterName = System.IO.Path.GetDirectoryName(fname) + @"\" + System.IO.Path.GetFileNameWithoutExtension(fname) + ExportExtension;
                            printer.paperSize = new System.Drawing.Rectangle(0, 0, 827, 1169);//A4
                            printer.LandScape = false;
                            printer.PrintExtents();
                            printer.PrintScaleToFit();
                            printer.CenterDrawingToPaper();
                            printer.PrintOut();
                            success = true;
                        }
                        else
                        {
                            if (string.Compare(ExportExtension, System.IO.Path.GetExtension(fname)) != 0)
                                success = document.SaveAs(System.IO.Path.GetDirectoryName(fname) + @"\" + System.IO.Path.GetFileNameWithoutExtension(fname) + ExportExtension);
                        }
                    }
                    if (success) PrintMessage(string.Format("{0,-40} ", System.IO.Path.GetFileName(document.FileName)) + "Finish");
                    else PrintMessage("Error Exporting " + fname);
                    document.OnPrompt -= new vdDocument.PromptEventHandler(document_OnPrompt);
                    document.OnProgress -= new VectorDraw.Professional.Utilities.ProgressEventHandler(document_OnProgress);
                    document.GenericError -= new vdDocument.GenericErrorEventHandler(document_GenericError);
                    document.OnLoadUnknownFileName -= new vdDocument.LoadUnknownFileName(document_OnLoadUnknownFileName);
                    document.OnIsValidOpenFormat -= new vdDocument.IsValidOpenFormatEventHandler(document_OnIsValidOpenFormat);
                    document.OnSaveUnknownFileName -= new vdDocument.SaveUnknownFileName(document_OnSaveUnknownFileName);
                    document.OnGetSaveFileFilterFormat -= new vdDocument.GetSaveFileFilterFormatEventHandler(document_OnGetSaveFileFilterFormat);
                    DocComponent.Dispose();
                }            void document_OnGetSaveFileFilterFormat(ref string saveFilter)
                {
                    saveFilter = "*.vdml|*.vdcl|*.dxf|*.dwg|*.svg|*.pdf|*.emf|*.HPG|*.bmp|*.jpg|*.png||";            }
                void document_OnSaveUnknownFileName(object sender, string fileName, out bool success)
                {
                    success = false;
                    vdDocument document = sender as vdDocument;
                    if (fileName.EndsWith(".dwg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        success = vdxFcnv.ConversionUtilities.SaveDwg(document, fileName);
                    }
                    else if (fileName.EndsWith(".dxf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        vdDXF.vdDXFSAVE dxf = new vdDXF.vdDXFSAVE();
                        success = dxf.SaveDXF(document, fileName);
                    }
                }            void document_OnIsValidOpenFormat(object sender, string extension, ref bool success)
                {
                    if (extension.EndsWith(".dwg", StringComparison.InvariantCultureIgnoreCase) ||
                        extension.EndsWith(".dxf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        success = true;
                    }
                }            void document_OnLoadUnknownFileName(object sender, string fileName, out bool success)
                {
                    success = false;
                    vdDocument document = sender as vdDocument;
                    if (fileName.EndsWith(".dwg", StringComparison.InvariantCultureIgnoreCase))
                    {
                        success = vdxFcnv.ConversionUtilities.OpenDwg(document, fileName);
                    }
                    else if (fileName.EndsWith(".dxf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        success = vdDXF.vdDXFopen.LoadFromStream(document, new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None));
                    }
                }
                void PrintMessage(string message)
                {
                    message = message.Replace("\r\n", "");
                    message = message.Replace("\n", "");
                    message += new string(' ', Console.BufferWidth - message.Length);
                    lock (Console.Out)
                    {
                        Console.SetCursorPosition(0, lineNo);
                        Console.Out.Write(message);
                    }
                }
                void document_GenericError(object sender, string Membername, string errormessage)
                {
                    vdDocument document = sender as vdDocument;
                    PrintMessage(string.Format("{0,-40} ", System.IO.Path.GetFileName(document.FileName)) + Membername + errormessage);
                } 
                void document_OnProgress(object sender, long percent, string jobDescription)
                {
                    if (percent == 0) percent = 100;
                    vdDocument document = sender as vdDocument;
                    PrintMessage(string.Format("{0,-40} ", System.IO.Path.GetFileName(document.FileName)) + jobDescription + " : " + percent.ToString() + "%");
                }            void document_OnPrompt(object sender, ref string promptstr)
                {
                    if (promptstr == null) return;
                    string str = promptstr;
                    str = str.Trim();
                    if (str == string.Empty) return;
                    vdDocument document = sender as vdDocument;
                    PrintMessage(string.Format("{0,-40} ", System.IO.Path.GetFileName(document.FileName)) + str);
                }
            }
        }
    }

        對(duì)于以上問(wèn)答,如果您有任何的疑惑都可以在評(píng)論區(qū)留言,我們會(huì)及時(shí)回復(fù)。此系列的問(wèn)答教程我們會(huì)持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。

    相關(guān)資料推薦:

    VectorDraw Developer Framework(VDF)示例


        如果您對(duì)想要購(gòu)買(mǎi)正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關(guān)問(wèn)題。

        關(guān)注慧聚IT微信公眾號(hào) ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。

    1561953111.jpg

    850×100.png


    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();