C#对象当前正在其他地方使用

执_念 2017-05-26 05:44:49
一个主窗体,两个打印窗口,主窗体创建线程监控usbI/O模块发来的信号,信号1模拟1窗体的打印按钮,信号2模拟2窗体的打印按钮,当运行起来触发的时候就报“对象当前正在其他地方使用”的错误。请大神帮忙,详细说一下怎么解决,谢谢!
...全文
1408 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
水哥阿乐 2017-05-27
  • 打赏
  • 举报
回复
楼主别急,这种图片大家也分析不了,慢慢找一下那个对象资源被占用,释放一下
执_念 2017-05-27
  • 打赏
  • 举报
回复
主窗体
public delegate void btnclick();
    public partial class Frmmain : Form
    {
        public event btnclick btnc;
        Thread test_thread;
        private void Frmmain_Load(object sender, EventArgs e)
        {
            test_thread = new Thread(test);
            test_thread.Start();
        }
        private void test()
        {
            try
            {
                while (true)
                {
                    string idi = ConfigurationManager.AppSettings["IDI"];
                    if (testDI(idi) == 0)
                    {
                        btnc();
                    }
                }
            }
        }
    }
子窗体中的方法
public void printbtn()
        {
            try
            {
                lock (locker)
                {
                    int intlsh = int.Parse(ConfigurationManager.AppSettings["liushuihao"]);
                    if (intlsh == 0)
                    {
                        string liu = ConfigurationManager.AppSettings["date"] + intlsh.ToString("000");
                        this.ccode.Text = dbb.Rows[0][0].ToString() + this.getserianumber(liu);
                        results = this.ccode.Text;
                        bcc.CreateBarCode(pictureBox1, results);
                    }
                    else
                    {
                        string liu = ConfigurationManager.AppSettings["date"] + intlsh.ToString("000");
                        this.ccode.Text = dbb.Rows[0][0].ToString() + this.getserianumber(liu);
                        results = this.ccode.Text;
                        bcc.CreateBarCode(pictureBox1, results);
                    }
                    PrintDocument pd = new PrintDocument();
                    pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                    pd.PrintController = new StandardPrintController();
                    pd.Print();


                    string lius = ConfigurationManager.AppSettings["date"] + intlsh.ToString("000");
                    results = dbb.Rows[0][0].ToString() + this.getserianumber(lius);
                    this.ccode.Text = results;
                    bcc.CreateBarCode(pictureBox1, results);
                    bool gone = SetConfigValue("liushuihao", results.Substring(results.Length - 3));

                    this.setdate();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
执_念 2017-05-27
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
那里不是写着“查看详细信息”么?
xuggzu 2017-05-26
  • 打赏
  • 举报
回复
贴出frmmain构造函数和相关初始化代码。
执_念 2017-05-26
  • 打赏
  • 举报
回复
引用 3 楼 ilikeff8 的回复:
你这个问题提的有点笼统,估计是没有lock或用mutex
试过加锁,但是没弄明白怎么加
执_念 2017-05-26
  • 打赏
  • 举报
回复
ilikeff8 2017-05-26
  • 打赏
  • 举报
回复
你这个问题提的有点笼统,估计是没有lock或用mutex
  • 打赏
  • 举报
回复
贴出抛出异常时的你的调试画面。
nikyotensai 2017-05-26
  • 打赏
  • 举报
回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧