如何摆脱所有这些异常弹出窗口? [英] How do I get rid of all these exception pop ups?

查看:73
本文介绍了如何摆脱所有这些异常弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个事件日志列表放入来自windows froms的 dataGridView 中,程序运行良好,它或多或少做了它需要做的事情,但是它将它放入 dataGridView ,当我滚动浏览 dataGridView 中的事件时,它会引发大量错误。



问题视频: https://youtu.be/Ixl7AatUiW0



我不知道他们来自哪里或从哪里开始修理它们。

你可以滚动浏览事件,但它会抛出这些错误并继续运行。



---------------- -------------------------------------------------- ----------------------------------------



I am putting a list of event logs into the dataGridView from windows froms, the program runs fine and it more or less does what it needs to do, but while it is putting it into the dataGridView and while I am scrolling through the events in the dataGridView it throws up a ton of errors.

Video of issue: https://youtu.be/Ixl7AatUiW0

I don't know where they are coming from or where to start to fix them.
You can sort of scroll through the events, but it throws up those errors and keeps running.

----------------------------------------------------------------------------------------------------------

public static class EventLogClassContainer
    {
        public static string EvlLocation { get; set; } = "";
        public static string EvlName { get; set; } = "Application";
        public static string evlLocationManual = "%Test.evt%";
        public static List<EventLogEntry> _LogEntries { get; private set; }

        public static void ReadEventLog()
        {
            EventLog evlLog = new EventLog(EvlName, ".");
            EventLogEntryCollection eventLogEntries = evlLog.Entries;
            int eventLogEntryCount = eventLogEntries.Count;
            foreach (EventLogEntry entry in evlLog.Entries)
            {
                //entry.Message
                _LogEntries = eventLogEntries.Cast<EventLogEntry>().ToList();
            }
        }

        public static void SetEvlName(string evlLocation)
        {
            Parser.FileNameFinder(evlLocation, 3);
        }

        public static void RELSystemTest()
        {
            EventLog evlLog = new EventLog("Application", ".");
            EventLogEntryCollection eventLogEntries = evlLog.Entries;
            int eventLogEntryCount = eventLogEntries.Count;
            _LogEntries = eventLogEntries.Cast<EventLogEntry>().ToList();
        }

        public static void ParseTest()
        {
            evlLocationManual = "K:\\Event Log\\Test\\Test.evt";
            ReadEventLog();
        }

        public static void setLogLocation(string input)
        {
            EvlLocation = input;
        }
    }



------------------------- -------------------------------------------------- -------------------------------




----------------------------------------------------------------------------------------------------------

// Open the log file
        private void OpenFile()
        {
            // Show file open dialog
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                // Create a dataset for binding the data to the grid.
                ds = new DataSet("EventLog Entries");
                ds.Tables.Add("Events");
                ds.Tables["Events"].Columns.Add("ComputerName");
                ds.Tables["Events"].Columns.Add("EventId");
                ds.Tables["Events"].Columns.Add("EventType");
                ds.Tables["Events"].Columns.Add("SourceName");
                ds.Tables["Events"].Columns.Add("Message");
                // Start the processing as a background process
                EventLogClassContainer.EvlLocation = openFile.FileName;
                worker.RunWorkerAsync(openFile.FileName);
            }
        }

        // Bind the dataset to the grid.
        private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            EventLogClassContainer.RELSystemTest();
            bs = new BindingSource(ds, "Events");
            Foo foo1 = new Foo("TEST PC");
            ComputerName.Add(foo1);

            bs.DataSource = EventLogClassContainer._LogEntries;
            //Bind fooList to the dataGridView
            dataGridView1.DataSource = bs;

            this.Invoke(pbHandler, new object[] { 100, 100 });
        }



------------------------------ -------------------------------------------------- --------------------------



以下例外情况:



DataGridView中发生以下异常:



系统.ArgumentException:参数无效。在System.Drawing.Image.FromStream(Stream stream,Boolean useEmbeddedColorManagement,Boolean validateImageData)



System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptionContext context,CultureInfo culture,Object价值)



System.Windows.Forms.Formatter.FormatObjectInternal(Object value,Type targetType.TypeConverter sourceConverter,TypeConverter targetConverter,String formatString,IFormatProvider formatInfo,Object formattedNullValue)在System.Windows.Forms.Formatter.FormatObject(Object value,Type targetType,TypeConverter sourceConverter,TypeConverter targetConverter,String formatString,IFormatProvider formatInfo,Object formattedNullValue,Object dataSourceNullValue)

at

System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value,Int32 rowIndex,DataGridViewCellStyle& cellStyle,TypeConverter valueTypeConverter,TypeConverter formattedValueTypeConverter,DataGridViewDataErrorContexts con文本)



要替换此默认对话框,请处理DataError事件。





DataGridView中发生以下异常:



System.ArgumentException:值'0'不是枚举'EventLogEntryType'的有效值。 />
at

System.ComponentModel.EnumConverter.ConvertTo(ITypeDescriptorContext context,CultureInfo culture,Object value,Type destinationType)

at

System.Windows.Forms.Formatter.FormatObjectInternal(Object value,Type targetType。 System.Windows.Forms.Formatter.FormatObject的TypeConverter sourceConverter,TypeConverter targetConverter,String formatString,IFormatProvider formatInfo,Object formattedNullValue)(Object value,Type targetType,TypeConverter sourceConverter,TypeConverter targetConverter,String formatString,IFormatProvider formatInfo,Object formattedNullValue,Object dataSourceNullValue)



System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value,Int32 rowIndex,DataGridViewCellStyle& cellStyle,TypeConverter valueTypeConverter,TypeConverter formattedValueTypeConverter,DataGridViewDataErrorContexts context)



要替换此默认对话框,请处理DataError事件。



我尝试过:



我试过通过每个 EventLogEntry 但没有成功。来自 List< EventLogEntry> 的数据似乎与dataGridView所要求的数据不匹配。似乎dataGridView正在寻找不存在的数据的图像。我已经尝试过调试,但它没有发现它运行正常的任何错误,它只是抛出每隔一次点击的异常,我不知道它来自哪里。



如果没有所有错误,我怎样才能正常工作。


----------------------------------------------------------------------------------------------------------

Exceptions below:

The following exception occurred in the DataGridView:

System.ArgumentException: Parameter is not valid. at System.Drawing.Image.FromStream(Stream stream, Boolean useEmbeddedColorManagement, Boolean validateImageData)
at
System.Drawing.ImageConverter.ConvertFrom(ITypeDescriptionContext context, CultureInfo culture, Object value)
at
System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType. TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue) at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
at
System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle & cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)

To replace this default dialog please handle the DataError event.


The following exception occurred in the DataGridView:

System.ArgumentException: The value '0' is not a valid value for the enum 'EventLogEntryType'.
at
System.ComponentModel.EnumConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
at
System.Windows.Forms.Formatter.FormatObjectInternal(Object value, Type targetType. TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue) at System.Windows.Forms.Formatter.FormatObject(Object value, Type targetType, TypeConverter sourceConverter, TypeConverter targetConverter, String formatString, IFormatProvider formatInfo, Object formattedNullValue, Object dataSourceNullValue)
at
System.Windows.Forms.DataGridViewCell.GetFormattedValue(Object value, Int32 rowIndex, DataGridViewCellStyle & cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context)

To replace this default dialog please handle the DataError event.

What I have tried:

I have tried going through each individual EventLogEntry with no success. The data from the List<EventLogEntry> seems to not match up with what dataGridView is calling for. It seems dataGridView is looking for an image for data which isn't there. I've tried debugging, but it isn't picking up any errors it runs fine, it just throws up exceptions every other click and I can't tell where it is coming from.

How can I get this to work properly without all the errors.

推荐答案

Quote:

我已经尝试过调试,但它没有发现它运行正常的任何错误,它只是抛出每隔一次点击的异常,我无法分辨它来自哪里。

I've tried debugging, but it isn't picking up any errors it runs fine, it just throws up exceptions every other click and I can't tell where it is coming from.



你的代码不好,因为它会抛出错误。

调试器不会选择任何错误,只是告诉你代码是什么。

你有责任检查它是否能做它应该做的事情。

-----

当你不明白你的代码是什么正在做或为什么它做它做的,答案是调试器

使用调试器来查看你的代码在做什么。只需设置断点并查看代码执行情况,调试器允许您逐行执行第1行并在执行时检查变量,这是一个令人难以置信的学习工具。



调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]



调试器在这里向您展示您的代码在做什么你的任务是与它应该做的事情进行比较。

调试器中没有魔法,它没有发现错误,它只是帮助你。当代码没有达到预期的效果时,你就会接近一个错误。


Your code don't fine because it throw errors.
The debugger don't pick any error, it just show you what is doing your code.
It is your duty to check that it do what it is supposed to do.
-----
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.


这篇关于如何摆脱所有这些异常弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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