开发者

Error info lost from worker thread

I would like to understand why the following behaviour happens and any ways to achieve what I need.

I have a main thread that spwans a backgorund worker to do some processing. I have a background worker completed even handler where I listen for any error. When there is an error I throw the error and allow it to float back to the main thread. I dont want to handle the error and show any message from the background worker.

But when the error is finally trapped in the main thread, I dont get to see the actual error message but I get an 'target invocation unknown' error. Would like to understand why and any ways to do such scenarios.

Comments: Added Source Code Sample as requested.The reason why WCF was added because this logic is coded in a WCF service scenario. Hope it makes more sense now.

 class ParentClass
开发者_JS百科    {
        static void main()
        {
            try
            {
                Thread t = new Thread(new ThreadStart(M1));
                t.Start();
                // ...
                // ...
            }
            catch
            {
                // here I dont see the error as 'date time conversion' 
                // but see a generic error as I mentioned
            }
        }

        static void M1()
        {
            try
            {
                Convert.ToDateTime("sss");
            }
            catch (Exception e)
            {
                // Here I see the error as 'error in date time conversion'
               throw; 
            }
        }
    }

Thanks, Mani


Without looking at code, it's hard to guess how you are passing the exception, but did you check the InnerException property of the Exception you receive. It may contain the information you are looking for. If there is no information, it could be that the code that is catching the exception and "floating" it may itself be generating an error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜