日期:2014-05-17  浏览次数:21219 次

紧急求助 调用打印机厂家的DLL 如何 多线程打印
厂家提供的POSDLL.dll 

C# code

    /// <summary>
    /// 北洋OPOS指令集二次开发包DLL调用  
    ///   
    public class BeiYangOPOS
    {
        const string _DllVer = "1.4";
        /// <summary>
        /// 获取动态库版本号
        /// </summary>
        public string GetDllVer
        {
            get { return _DllVer; }
        }


        /// <summary>
        /// 设备打开后的句柄
        /// </summary>
        public IntPtr POS_IntPtr;

//打开打印机 
        [DllImport("POSDLL.dll", CharSet = CharSet.Ansi)]
      public static extern IntPtr POS_Open([MarshalAs(UnmanagedType.LPStr)]string lpName,uint nComBaudrate,uint nComDataBits,uint nComStopBits,uint nComParity,uint nParam);
//关闭打印机
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_Close();
//输出文本
        [DllImport("POSDLL.dll", SetLastError = true)]
        public static extern IntPtr POS_S_TextOut([MarshalAs(UnmanagedType.LPStr)]string pszString,uint nOrgx, uint nWidthTimes, uint nHeightTimes,uint nFontType, uint nFontStyle);
}




C# code


            foreach (KeyValuePair<string, PosPrinter> pos in poss) //循环所有打印机
            {
                pos.Value.Work();              //执行打印机任务
            }





然后打印机任务里是这样写的

C# code


        public void Work()
        {

            Thread worker = new Thread(new ThreadStart(PrintWork));
            worker.Start();
        }



    public void PrintWork()
        {
            string err = string.Empty;
          opos.OpenNetPort(ip);
            foreach (string Work in Works)
            {
                BeiYangOPOS.POS_S_TextOut(Work, 0, 1, 2, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_STYLE_NORMAL);
                BeiYangOPOS.POS_S_TextOut(this.ip, 0, 1, 3, opos.POS_FONT_TYPE_STANDARD, opos.POS_FONT_STYLE_NORMAL);
                BeiYangOPOS.POS_FeedLine();
                BeiYangOPOS.POS_FeedLine();
                BeiYangOPOS.POS_FeedLine();
                BeiYangOPOS.POS_FeedLine();
                BeiYangOPOS.POS_FeedLine();
                BeiYangOPOS.POS_CutPaper(0, 200);
                BeiYangOPOS.POS_FeedLine();
                BeiYangOPOS.POS_FeedLine();

            }
         opos.ClosePrinterPort();




由于厂家提供的dll 里 都必须是static 所以打印的内容都窜了共享冲突 不同的任务都打印到某一台去了 有没有办法解决这个问题