Windows 窗体未处理的异常崩溃

问题描述

我有适合我的 winforms 应用程序处理未处理异常代码。但是我的应用程序仍然崩溃。

在这个阶段,我确实不明白为什么会出现这种行为。感谢您的帮助。

这是我的代码

 [STAThread]
    private static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        bool result;
        var mutex = new System.Threading.Mutex(true,"MyApplication",out result);
        if (!result)
        {
            MessageBox.Show("Another instance is already running.");
            return;
        }
        Application.ThreadException += ApplicationThreadException;
        Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
        AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
        Memory.frmMain = new MainForm();
        Application.Run(new MyApplicationContext());
        GC.KeepAlive(mutex);
    }
    public static void CurrentDomainUnhandledException(object sender,UnhandledExceptionEventArgs e)
    {
        MessageBox.Show(((Exception)e.ExceptionObject).Message);
        ((Exception)e.ExceptionObject).AddLog();
        Memory.processtranslations.IsProcessing.Enabled = true;
    }
    public static void ApplicationThreadException(object sender,System.Threading.ThreadExceptionEventArgs e)
    {
        MessageBox.Show(e.Exception.Message);
        e.Exception.AddLog();
        Memory.processtranslations.IsProcessing.Enabled = true;
    }

解决方法

尝试将 import React,{useEffect,useState} from 'react'; import {Text,View,StyleSheet,Image} from 'react-native'; import database from '@react-native-firebase/database'; export default function New() { const [data,setData] = useState([]) const getData = async () => { const donorsData = []; database() .ref('users') .orderByChild('isDonor') .equalTo(true) .once('value') .then((results) => { results.forEach((snapshot) => { // console.log(snapshot.key,snapshot.val()); // console.log(snapshot.val()); donorsData.push(snapshot.val()); }); // console.log('aft',donorsData); }); setData(donorsData) } useEffect(()=>{ getData() },[]) return ( <View style={styles.container}> {data.lenght>0 && data.map((v,i) => { return ( <View key={v.uid} style={{ backgroundColor: 'white',padding: 10,margin: 5,borderRadius: 10,}}> <Text>{v.name}</Text> <Text>{v.email}</Text> <Image source={{uri: v.photo}} style={{height: 150,flex: 1}} /> </View> ); })} </View> ); } 属性添加到您的 Main 方法。更重要的是,让你的主循环进入 try..catch:

[HandleProcessCorruptedStateExceptions]

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...