首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

BeginInvoke最后一个参数没有意义?解决办法

2013-10-18 
BeginInvoke最后一个参数没有意义? 在做例子是发现,BeginInvoke最后一个参数没有任何意义?传一个NULL,或放

BeginInvoke最后一个参数没有意义?
 
在做例子是发现,BeginInvoke最后一个参数没有任何意义?
传一个NULL,或放个什么进去看不到任何变化。


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ASY
{
    public partial class Form1 : Form
    {
        public delegate string delegateInvoke(string parm);
        public delegate string delegateAppendText(string msg);

        public Form1()
        {
            InitializeComponent();
        }

        public string InvokedMethod(string parm)
        {          
            delegateAppendText da = new delegateAppendText(InvokedMethod);
            if (textBox1.InvokeRequired)
            {
                textBox1.Invoke(da, parm);
            }
            else
            {
                textBox1.Text = parm;
            }
            return "Asy called," + parm  ;
        }

        private void button1_Click(object sender, EventArgs e)
        {
             delegateInvoke delegateinvoke = new delegateInvoke(InvokedMethod);
             delegateinvoke.BeginInvoke("ok", new AsyncCallback(callComplete), null);
        }

        private void callComplete(IAsyncResult ir)
        {
            delegateInvoke di = (delegateInvoke)ir.AsyncState;           
            di.EndInvoke(ir);         
        }
    }
}

[解决办法]
你可以附加一个参数,当你同时调用几个线程的时候,这个参数就很有用。用来区分不同的线程。

热点排行