• C#中线程调用带有参数的方法


    c#为我们提供thread可以这么用:

    Thread t = new Thread(new ThreadStart(ScreenMonitor));
    t.Start();

    public void ScreenMonitor()
    {         
     //操作
     }

    如果想在方法中传入参数怎么办?并且还不止一个参数!

            struct ImageParam
            {
                public int a;
                public int b;
                public int c;
                public int d;
            }
    
            public void ScreenMonitor(Object args)
            {
                para = (ImageParam)args;
                int aa = para.a;
                int bb = para.b;
                int cc = para.c;
                int dd = para.d;
                Bitmap myImage = new Bitmap(aa, bb);
                Graphics g = Graphics.FromImage(myImage);
                g.CopyFromScreen(new Point(cc, dd), new Point(0, 0), new Size(aa, bb));
                String picpath = @"d:\test.jpg";
                myImage.Save(picpath);
                g.Dispose();
                myImage.Dispose();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Thread t = new Thread(ScreenMonitor);
                ImageParam imgPara = new ImageParam();
                imgPara.a = aa;
                imgPara.b = bb;
                imgPara.c = cc;
                imgPara.d = dd;
                t.Start((ImageParam)imgPara);    
              }
  • 相关阅读:
    位置匹配
    匹配重复
    使用元字符
    匹配一组字符
    匹配任意单个字符
    python-全局替换程序
    python37-encode与decode
    python37-能检测文件编码的模块
    super方法
    类-易错题
  • 原文地址:https://www.cnblogs.com/zhengbn/p/3103535.html
Copyright © 2020-2023  润新知