public void cs_Click(object sender, EventArgs e) { //Thread threadForm = new Thread(new ThreadStart(this.ReadData)); //threadForm.Start(); Thread thread = new Thread(new ThreadStart(InvokeControl)); thread.Start(); //AsyncEventHandler asy = new AsyncEventHandler(ShowForm); //asy.BeginInvoke(new AsyncCallback(CallBackMethod), asy); } //private void ThreadFunc() //{ // MethodInvoker mi = new MethodInvoker(this.ShowForm); // this.Invoke(mi); //} private void ShowForm() { DataAcquire_View dav = new DataAcquire_View(); dav.Show(); } private void ReadData() { if (seo_acquire().Count > 0) { Seo_acquire.content = PostDecryptContainer.DecryptContainer(LinkCurrent.GetValue("//mass", "handlecj"), "a=edit&p=" + seo_acquire()[seo_dataAcquire.SelectedItems[0].Index].path + ""); Seo_acquire.dv_title = seo_acquire()[seo_dataAcquire.SelectedItems[0].Index].title; } } //void CallBackMethod(IAsyncResult ar) //{ // ((AsyncEventHandler)ar.AsyncState).EndInvoke(ar); //} private void InvokeControl() { DelegateControl dc = new DelegateControl(ShowForm); //dc += new DelegateControl(ReadData); if (this.InvokeRequired) { this.Invoke(new DelegateControl(dc)); } else { this.ShowForm(); } } public delegate void DelegateControl();
我现在调用子窗口,父窗口就会卡着不动,一直等到子窗口数据加载完毕,父窗口才能用,怎么样能让两个互不影响啊
thread.IsBackground = true;变为后台线程 试试 希望能帮到你
问题描述的不是很清楚,没有明确说明2个窗体之间的关系,是MDI窗体类型还是A窗体中,点击某个按钮后打开了B窗口(子窗口) ?
加载数据很慢的话,可以考虑使用异步方法(Beginxxxx)
A窗口点击一个按钮弹出B窗口