ShowDialog()上的问题 [英] Issue on ShowDialog()

查看:134
本文介绍了ShowDialog()上的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用ShowDialog()方法遇到问题。它在WTS服务器中运行,并且有瘦客户端登录该服务器以运行应用程序。

我遇到了一些问题,当用户打开窗口时,系统崩溃而且他们不能做更多的事情,然后我不得不强制注销他们的瘦客户端。

我放了一个计时器,如果线程在30秒内未关闭,系统会注销以避免这些崩溃,然后记录再次自动,但直到我无法解决真正的问题。

然后我在ShowDialog调用中放了一个try / catch块,但它根本没有抓到任何东西,系统仍然崩溃。



我根本无法调试,因为它不会一直发生。在我的电脑里,它从来没有发生过,而且它们大部分时间都是正常使用的,但有时这种情况会发生,这真的让我感到烦恼。



任何人都有可以帮到我的东西?



I'm having an issue using the method ShowDialog() in my application. It runs in a WTS server, and there are thin clients that log in that server to run the application.
I was having some problems that when the user opens the window, the system just crashes and they cannot do anything more, then I had to force the logoff of their thin clients.
I put a timer that if the thread isn't closed in 30s the system logs off to avoid these crashes, and then log on again automatically, but it's just until I can't resolve the real issue.
Then I put a try/catch block in the ShowDialog call, but it simply doesn't catch anything and the system still crashes.

I simply can't debug that because it doesn't happens all the time. In my PC it never happened, and they use most of the time normally, but sometimes this happens and that really bugs me.

Anyone has something that could help me?

try
    {
        //I tried like this:
        //base.ShowDialog();

        //and then like this (FPrincipal.ActiveForm is the Form that call this modal window)
        base.ShowDialog(FPrincipal.ActiveForm);
    } 
    catch (ArgumentException e)
    {
        sendsEmail();
        
    } 
    catch (InvalidOperationException e)
    {
        sendsEmail();
    }





这是一个旧项目,它是在VS2008中制作的,并使用.net Framework 2.0。



非常感谢!



This is a old project, it was made in VS2008 and uses .net Framework 2.0.

Thanks a lot!

推荐答案

请尝试以下代码。我想你可以找到原因,或者至少停止崩溃。



Please try the following code. I think you can find the reason, or at least stops crashing.

using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace Test_UnhandledException
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            // unhandled exception handling
            Application.ThreadException += Application_ThreadException;
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            // starting form1
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            AddLog((Exception)e.ExceptionObject);
        }

        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            AddLog(e.Exception);
        }

        static void AddLog(Exception exception)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(@"d:\tmp\app.log", true))
                {
                    sw.WriteLine(exception.ToString());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}


这篇关于ShowDialog()上的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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