简体   繁体   English

目标抛出了异常错误的应用程序崩溃

[英]Application crash with error Exception has been thrown by the target

i have Winform application who run all the files within listbox, i am using Pcapdotnet DLLs to send packets into my network adapter, the process is that i am taking Wireshark capture file and with this file send all the packets. 我有运行列表框中所有文件的Winform应用程序,我正在使用Pcapdotnet DLL将数据包发送到我的网络适配器中,过程是我正在获取Wireshark捕获文件,并使用此文件发送所有数据包。 each file will run with BackgroundWorker and after it's finished the next time in my listbox srart to run etc. i added a Checkbox and when this Checkbox in checked state all the files run in the same time simultaneous. 每个文件将与BackgroundWorker一起运行,并在下一次完成后在我的列表框srart中运行等。我添加了一个复选框,当此复选框处于选中状态时,所有文件同时在同一时间运行。 when it's running my application crash with error: Exception has been thrown by the target of an invocation in: 当它运行时,我的应用程序崩溃并出现错误:调用的目标在以下位置抛出了异常:

static void Main()
{
    Adapters addr = new Adapters();
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new mainWindow());
}

the error received in the last line (Application.Run(new mainWindow());) 最后一行中收到的错误(Application.Run(new mainWindow());)

this is my code who handle in simultaneous running: 这是我的代码,可以同时运行:

        for (int i = 0; i < listBoxFiles.Items.Count; i++)
        {
            string filePath  = (string)listBoxFiles.Items[i];
            playCount = 0;

            BackgroundWorker bgWsim = new BackgroundWorker();
            bgWsim.WorkerReportsProgress = true;
            bgWsim.ProgressChanged += new ProgressChangedEventHandler(bgW_ProgressChanged);
            bgWsim.DoWork += new DoWorkEventHandler(
            (s3, e3) =>
            {
                while ((playCount < numberOfLoops) && (bContinuePlay)) //play the capture
                {
                    for (int k = 0; (k < listBoxFiles.Items.Count) && (bContinuePlay); k++)
                    {
                        class = new myClass(filePath , playSpeed);

                        class.evePacketProgress += new class.dlgPacketProgress(
                            (progressCount) =>
                            {
                                bgWsim.ReportProgress(progressCount, class);
                            });

                        if (selectedAdapter != null)
                        {
                            bContinuePlay = class.playCapture(selectedAdapter._packetDevice);
                        }

                        playCount++;
                        Thread.Sleep((int)delay);
                    }
                }
            });

            bgWsim.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
            (s3, e3) =>
            {
                groupBoxSelect.Enabled = true;
                groupBoxOptions.Enabled = true;
                groupBoxInfo.Enabled = true;
                btnPlay.Enabled = true;
            }
            );

            bgWsim.RunWorkerAsync();
        }

how can i debug this error and find the problem ? 我如何调试此错误并查找问题?

error screenshot: 错误截图:

http://i42.tinypic.com/2ainbqp.jpg http://i42.tinypic.com/2ainbqp.jpg

A ProgressBar has Maximum and Minumum properties that are used to define the range of values that it will accept (defaulting from 0 to 100). ProgressBar具有“ Maximum和“ Minumum属性,用于定义它将接受的值的范围(默认为0到100)。 If you try to set the Value property to a number outside of the range, it, will throw an ArgumentException. 如果尝试将Value属性设置为超出范围的数字,它将抛出ArgumentException。 See here . 这里

I think the problem is the RunWorkerCompleted event since its called by the async thread.You need to edit controls from Windows Forms on their own thread you can do this by invoking the control. 我认为问题是RunWorkerCompleted事件,因为它是由异步线程调用的。您需要在自己的线程上从Windows Forms编辑控件,您可以通过调用控件来实现。

Example : (with lambda) 示例:(带有lambda)

        private static void runOnThread(Control x, Action logic)
    {
        if (x.InvokeRequired)
        {
            x.Invoke(logic);
        }
        else
        {
            logic();
        }
    }

You will call this as follwed: 您将其称为:

runOnThread(groupBoxSelect,() => groupBoxSelect.Enabled = true );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WPF应用程序中的调用目标已引发异常 - Exception has been thrown by the target of an invocation in wpf application 配置错误-调用目标已引发异常 - Configuration Error - Exception has been thrown by the target of an invocation 错误“VS2013中的调用目标已抛出异常” - Error “Exception has been thrown by the target of an invocation” in VS2013 奇怪的错误:调用的目标引发了异常 - Strange error: Exception has been thrown by the target of an invocation Hazelcast DotNet客户端错误:调用的目标引发了异常 - Hazelcast DotNet client Error: Exception has been thrown by the target of an invocation DbGeography.PointFromText错误调用的目标引发了异常 - DbGeography.PointFromText error Exception has been thrown by the target of an invocation 如何解决“调用目标抛出异常”。 这个错误 - How to solve “Exception has been thrown by the target of an invocation.” this error SSIS:调用目标已抛出错误异常 - SSIS: Error Exception has been thrown by the target of an invocation 是什么导致此错误“调用目标已引发异常”? - What Generates This Error 'Exception has been thrown by the target of an invocation'? 调用的目标已引发异常 - SSIS 脚本任务错误 - Exception has been thrown by the target of an invocation - SSIS Script Task Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM