473,748 Members | 4,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Blank tab page when switching tab pages inside a thread

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.

When you run the application, do not click on the 2nd tab page.
Instead, click on the button. The tab page will switch to the 2nd tab
page but it will be blank (or empty). The label that you placed on the
2nd tab page is not visible. It's Visible property is in fact set to
true if you were to interrogate the control's properties.

Now try the whole thing again. Stop the program and start it again.
This time, before clicking the button, use the mouse and select the
2nd tab page. Now go back to the first tab page and press the button.
The label on the 2nd tab page now shows up.

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?

Thanks,
Johann
Nov 16 '05 #1
2 2401

"Johann Blake" <jo*********@ya hoo.com> wrote in message
news:d8******** *************** *@posting.googl e.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/...#windows.forms for
more information.

Regards,
Sami
Nov 16 '05 #2
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" <jo*********@ya hoo.com> wrote in message
news:d8******** *************** *@posting.googl e.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/...#windows.forms for
more information.

Regards,
Sami

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
13593
by: connoisseur.infotech | last post by:
We have a website we need to open popup under following conditions 1) When user close the browser either via X button or alt + f4, file -> Close 2) when he changes URL and goes to some other site. 3) but it should not open the popup window till the user is on same website. we have tried lot of combinations but till date nothing there.
6
4704
by: noway | last post by:
I have greated a report and have included a page break in it. The report breaks were it is supposed to but then it creates a blank page between the two pages. Since this report will print out approx 20 pages (without the blank pages) it is large waste of paper. I have tested the report by setting the data source so that only one page will print and all the data fits on page. I have checked all the printing parameter, set the print magins...
15
4777
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is not validate based on some given rules. I also have a custom error handling page to show the...
4
2071
by: Jeremy Holt | last post by:
Hi, In a windows.forms application I would BeginInvoke a delegate on the UI thread to collect data from a database. When the call returns to the AsyncCallback, if the Control.InvokeRequired = True, I would then have the Control.BeginInvoke(New AsyncCallback(AddressOf GetDataCallback), New Object() {ar}). How would one achieve the same thing on an asp.net page (without using a webseervice)? In the code below, because the...
2
2230
by: Amir | last post by:
I really hope someone can explain this behavior. I have spend quite a bit of time and tried a bunch of things, so far nothing has worked. I have a page on which I have a datagrid with template columns. I perform regular expression validations in the EditItemTemplate for the fields that require such validation. The datagrid is inside a div tag to make it scrollable. I have implemented the solution to freeze header for this grid - the...
2
2449
by: JohnGates | last post by:
In VB.net, I have win form programs that do database update operations that take several minutes or longer. Several actions such as switching windows or clicking a control during these operations leave me with a blank form (all white space inside the form borders) or with a frozen form that will not display refreshed controls. When the db operations are done, the forms repaint just fine. What’s happening and what can I do about it?...
5
2527
by: hman | last post by:
Forgive me if this is the wrong group to post this in, it's my first post. I have a web site that uses session variables and cookies. In-house and at most clients the web sites functions great, exactly how it should behave. However, at a few sites, the users will get the login page and as soon as they submit, they get served a page with just the banner image on top and blank underneath it. The page is two frames, top and bottom with...
1
4852
by: mbruyns | last post by:
i have been trying (and sometimes succeeding) to use the modalpopupextender to show various panels of controls on my asp pages. the strange problem that i keep on running into is that sometimes it works, displaying an awesome popup, while other times, it doesn't show a popup at all, but rather just page posts back and the panel becomes visible at the bottom of the page (where it is situated in the designer). what is even stranger to me is that...
3
1576
by: Andy B | last post by:
I have a web form that has controls to be modified on it. The class that will modify the controls is not contained inside the page code. How would I best pass the controls to the external class?
0
8989
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9243
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2213
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.