threading & suspendlayout

2

2G

Hi,

I've a usercontrol that fills a listview with data from my db, I had
this.SuspendLayout() in the beginning and this.ResumeLayout at the end of
the function that loads the data and all worked fine. But now that I have
threaded the function (refreshdata), the SuspendLayout and ResumeLayout()
doesn't work any more, I tried solving it with Invoke() but with no succes.
public UserControl1(){

this.SuspendPaint += new DSuspendPaint(this.SuspendPaintProc);



}



private delegate void DSuspendPaint(bool b);

private event DSuspendPaint SuspendPaint;

private void SuspendPaintProc(bool b){

if(b)

this.listView1.SuspendLayout();

else

this.listView1.ResumeLayout();

}

public void RefreshData(){

this.Invoke(this.SuspendPaint, new object[]{ true });

...load data and fill listview

this.Invoke(this.SuspendPaint, new object[]{ false });

}
 
J

Jon Skeet [C# MVP]

2G said:
I've a usercontrol that fills a listview with data from my db, I had
this.SuspendLayout() in the beginning and this.ResumeLayout at the end of
the function that loads the data and all worked fine. But now that I have
threaded the function (refreshdata), the SuspendLayout and ResumeLayout()
doesn't work any more, I tried solving it with Invoke() but with no succes.
public UserControl1(){

this.SuspendPaint += new DSuspendPaint(this.SuspendPaintProc);
}

You're using Invoke for the SuspendLayout and ResumeLayout calls, but
it looks like you're still filling the listview from your worker
thread, which you shouldn't be. *Everything* which touches the UI
should be done from the UI thread.

I'm not sure why you've got a SuspendPaint event, either...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top