Asp.net中的线程异常处理 [英] Exception handling with threads in Asp.net

查看:85
本文介绍了Asp.net中的线程异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在线程内部有一个线程.我使用了 try catch block ,所以当发生异常时,它将在标签中显示,例如...

My code has a thread inside thread. I used try catch block, so when an exception occurs, it will be shown in label like...

ThreadStart threadstartprint = () => CreatePDF();
Thread threadprint = new Thread(threadstartprint);

CreatePDF()
{
     try
     {
     }
     catch(Exception ex)
     {
          lbl.text=ex.message;
     }
}


我的问题是,即使发生异常,也不会显示.
有什么方法可以捕获线程中的异常并显示该异常吗?


My problem is that even if an exception is occurred, but it is not showed.
Is there any way to catch exception in thread and show that exception ?

推荐答案

您尚未启动线程,因此控件未调用我正在获取的CreatePDF()方法根据您指定的代码.

您更新的代码应如下所示:-尝试使用此代码可能会有所帮助...
You have not started your thread so control is not invoking CreatePDF() method Which i am getting by your given code.

Your updated code should be like below :- Try this one may help...
ThreadStart threadstartprint = () => CreatePDF();
Thread threadprint = new Thread(threadstartprint);
threadprint.Start();

CreatePDF()
{
     try
     {
     }
     catch(Exception ex)
     {
          lbl.text=ex.message;
     }
}


这篇关于Asp.net中的线程异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆