Re: Blank tab page when switching tab pages inside a thread
From: coughlla (coughlla_at_discussions.microsoft.com)
Date: 08/06/04
- Next message: Timo: "Re: RE: SMS Sdk??"
- Previous message: kscdavefl: "Re: Fill a datalist with names of tables"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 6 Aug 2004 09:11:01 -0700
I ran into this problem, but I have to use multiple threads due to other
functions of our system. The fix is to make the method that switches the
tabs threadsafe by creating a delegate and using the Forms.Invoke method.
"Sami Vaaraniemi" wrote:
>
> "Johann Blake" <johannblake@yahoo.com> wrote in message
> news:d85eb46.0407210008.bcea8d3@posting.google.com...
> > The following is a bug I have discovered using tab pages and threads
> > and I am looking for a workaround.
> >
> > Create a new Windows Forms application and add a tab control with two
> > tab pages. Add a label to each tab page. On the first tab page add a
> > button. When the button is pressed the code behind the button creates
> > a thread and starts that thread. The only thing that the thread is to
> > do is to switch from the first tab page to the 2nd tab page. This is
> > done by setting the SelectedTab property of the tab control to the 2nd
> > tab page.
> >
> [snip]
> > This problem only occurs when the switching is within a thread. If you
> > do the switching within the button's click event without using a
> > thread, this problem never occurs. It appears therefore that when the
> > thread dies, it wipes the label off of the 2nd tab page. All the
> > methods I've tried to redraw the control fail to redraw it again. In
> > fact, if you put a message box inside the thread just prior to exiting
> > the thread, the label will get redrawn but as soon as you click the
> > message box's OK button and the thread terminates, the label will be
> > erased from the form. The label still exists, at least in code, but
> > nothing visual exists.
> >
> > Any clues how to get around this?
>
> Yes. Stick to the first golden rule of Windows Forms threads programming:
> never access a control or a form directly from a non-UI thread. See Jon
> Skeet's FAQ at
> http://www.yoda.arachsys.com/csharp/multithreading.html#windows.forms for
> more information.
>
> Regards,
> Sami
>
>
>
- Next message: Timo: "Re: RE: SMS Sdk??"
- Previous message: kscdavefl: "Re: Fill a datalist with names of tables"
- Messages sorted by: [ date ] [ thread ]