如何修复“ vs.exe停止工作”错误?

时间:2019-06-21 04:14:38

标签: c# winforms dllimport

我有一个Windows窗体代码,在其中单击按钮时,应从DLL中执行该功能。我使用了后台工作者功能。

DLL入口点错误反复发生,现在,vs停止工作。请帮我解决这个问题:)

可以使用其他任何方法吗?

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
    Bitmap[] test = new Bitmap[50];
    private BackgroundWorker _worker = null;
    System.Threading.ManualResetEvent _busy = new System.Threading.ManualResetEvent(false);


   public Form1()
    {
        InitializeComponent();
    }

   [DllImport("\\bin\\simpleDll.dll", EntryPoint = "thesholdImage")]
   public static extern String thesholdImage();

    private void button1_Click(object sender, EventArgs e)
    {
        _worker = new BackgroundWorker();
        _worker.WorkerSupportsCancellation = true;
        _worker.DoWork += new DoWorkEventHandler((state, args) =>
        {
           for (int i = 0; i < 50; i++)
                {
                    if (_worker.CancellationPending)
                    {
                        return;
                    }

                    Bitmap bmp = new Bitmap("D:/01_datasets/Bitmaps/" + Convert.ToString(i) + ".bmp");

                    test[i] = bmp;
                    pictureBox1.Image = test[i];

                    textBox1.Text= thesholdImage();                      
                }
        });

        _worker.RunWorkerAsync();
        button1.Enabled = false;
        button2.Enabled = true;

    }


    private void button2_Click(object sender, EventArgs e)
    {
        button2.Enabled = false;
        button1.Enabled = true;

         _busy.Set();
        _worker.CancelAsync();

    }
  }
}

0 个答案:

没有答案