如何解决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]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。