473,657 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug in .NET Tab Control? Help!

I have an app written in C# (obviously). Here is my dilemma:

The form loads, instantiates a bunch of worker threads that execute one at a
time. When one finishes, it starts the next one in line. I have about 5
datagrids on 5 different tab pages in a tab control. What I'm using the
Threads for is pretty basic: get data from a database and fill a datagrid. I
use delegates throughout to allow the worker thread to call the
'FillDataGrid' method in the main thread (the form thread). I've had
problems before with threads not accessing other threads controls which is
why I use the delegates. But still it crashes with the following:

An unhandled exception of type 'System.Argumen tException' occurred in
system.windows. forms.dll

Additional information: Controls created on one thread cannot be parented to
a control on a different thread.

I decided to add another tab page (out of pure imagination) as the first tab
page in the control. voila! now everything loads properly (without changing
any code whatsoever). Problem is, I try to programmaticall y remove the
temporary page (with a generic "please wait while loading" message). It
removes the page fine, but on the next page in line, all the controls
dissappear. If I don't change or remove tab pages programmaticall y, all the
controls stay intact. I'm not sure what I am missing, and leaving the temp
page intact is just ugly. Anybody know what I'm missing?
Nov 16 '05 #1
5 2091
slylos <sl****@discuss ions.microsoft. com> wrote:
I have an app written in C# (obviously). Here is my dilemma:

The form loads, instantiates a bunch of worker threads that execute one at a
time. When one finishes, it starts the next one in line. I have about 5
datagrids on 5 different tab pages in a tab control. What I'm using the
Threads for is pretty basic: get data from a database and fill a datagrid. I
use delegates throughout to allow the worker thread to call the
'FillDataGrid' method in the main thread (the form thread). I've had
problems before with threads not accessing other threads controls which is
why I use the delegates. But still it crashes with the following:

An unhandled exception of type 'System.Argumen tException' occurred in
system.windows. forms.dll

Additional information: Controls created on one thread cannot be parented to
a control on a different thread.


That suggests your threading isn't what you think it is. Are you sure
you're using Control.Invoke rather than calling Invoke or BeginInvoke
directly on the delegate?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
I'll try to give you more of my code without running out of space here:

I've got a Windows form where the tabcontrol is located
(frmScheduleReq uestsAdmin)
I've got a db layer that connects to a web service that I built to retreive
the records from the database (tsClientWebSer viceConnection. dll)
the db layer has a method 'GetPendingSche duleRequests'. here is the
delegates in the db layer:

------------------------------------>db layer
code<----------------------------------------
public delegate void PendingSchedule RequestsComplet e(DataSet dsPending);
public static PendingSchedule RequestsComplet e PendingRequests Complete;

//here is the method that retrieves the pending requests

public void GetPendingSched uleRequests()
{
MyWebServiceObj ect obj = new MyWebServiceObj ect();//name changed =^)
DataSet dsPending;

try
{
dsPending = obj.GetPendingR equests();
}
catch(System.Ne t.WebException we)
{
//save error info to file
}

if (PendingRequest sComplete != null) //invoke delegate
{
PendingRequests Complete(dsPend ing);
}
}
------------------------------------>db layer
code<----------------------------------------

and here is the delegate connection and thread start
------------------------------------>Form
code<------------------------------------------
//form_load
private void frmScheduleRequ estAdmin_Load(o bject sender, System.EventArg s e)
{
tsClientWebServ iceConnection ts = new tsClientWebServ iceConnection;
tsClientWebServ iceConnection.P endingRequestsC omplete = new
tsClientWebServ iceConnection.P endingScheduleR equestsComplete (LoadPendingSch eduleRequests);
Thread tGetPending = new Thread(new
ThreadStart(ts. GetPendingSched uleRequests));

tGetPending.Sta rt();
}
//target for delegate
private void LoadPendingSche duleRequests(Da taSet dsPending)
{
dsLocalPendingC opy = dsPending.Copy( );
dgPending.DataS ource = dsLocalPendingC opy.Tables[0];
ProgressComplet e();
}
//progress complete handles tab removal
private void ProgressComplet e()
{
tcTabs.TabPages .Remove(tpLoadi ngPage);
}

------------------------------------->Form
code<-------------------------------------------

when ProgressComplet e executes, thats when the next tab in line loses its
controls ... please help!!

That suggests your threading isn't what you think it is. Are you sure
you're using Control.Invoke rather than calling Invoke or BeginInvoke
directly on the delegate?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
slylos <sl****@discuss ions.microsoft. com> wrote:
I'll try to give you more of my code without running out of space here:

I've got a Windows form where the tabcontrol is located
(frmScheduleReq uestsAdmin)
I've got a db layer that connects to a web service that I built to retreive
the records from the database (tsClientWebSer viceConnection. dll)
the db layer has a method 'GetPendingSche duleRequests'. here is the
delegates in the db layer:


It looks like you're doing exactly what the error message is
complaining about - updating a control from a non-UI thread.

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml

Just "using delegates" doesn't do everything automatically - you need
to call Control.Invoke/BeginInvoke appropriately.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Well I'm not having a problem with the error message; that went away as soon
as I added a tabpage in front of the first tabpage with the datagrid. The
problem I'm having is when I programmaticall y remove that first (temp)
tabpage to expose the tabpage with the datagrid, all the controls on the tab
with the datagrid disappear(inclu ding the datagrid, but not their tabpage
parent).

Like I said, I do the same exact thing in another form (with different data,
same controls i.e. tab pages/datagrids) and I never have problems. The
difference between that form and this form is the tabpage on that form is 3rd
in the tabpage order, and on the new form, its the first tabpage in the
order. The problem I'm having is controls mysteriously disappearing . . .
Nov 16 '05 #5
slylos <sl****@discuss ions.microsoft. com> wrote:
Well I'm not having a problem with the error message; that went away
as soon as I added a tabpage in front of the first tabpage with the
datagrid. The problem I'm having is when I programmaticall y remove
that first (temp) tabpage to expose the tabpage with the datagrid,
all the controls on the tab with the datagrid disappear(inclu ding the
datagrid, but not their tabpage parent).
Just adding a tabpage hasn't fixed your threading error though. I'm not
sure why the error message went away, but the problem hasn't.
Like I said, I do the same exact thing in another form (with
different data, same controls i.e. tab pages/datagrids) and I never
have problems. The difference between that form and this form is the
tabpage on that form is 3rd in the tabpage order, and on the new
form, its the first tabpage in the order. The problem I'm having is
controls mysteriously disappearing . . .


Just because something has worked in the past doesn't mean it was
guaranteed to work, or that you weren't doing things wrong. If you
access the UI from a different thread, you shouldn't be doing that.
Your code appears to be doing that. Fix it (everywhere you're doing it,
not just in the place where you're seeing problems), and then if it
still doesn't work, we'll look again.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

6
11276
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header" Src="WebControls/Header.ascx" %> The web user control contains the following server controls
11
2618
by: -D- | last post by:
How can I turn the visibility of the xml control on or off? <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopNavBar.ascx.cs" Inherits="compass.user_controls.TopNavBar" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <table cellSpacing="0" cellPadding="0" border="0"> <colgroup span="1" align="left" width="50%"> </colgroup> <colgroup span="1" align="right" width="50%"> </colgroup>
9
2113
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0's ImageMap Control to create 2 imagemaps, one directly below the other. When I do this a thin blank space appears between them. After several days of frustration I realized that the difference between what the ImageMap Control outputs and the html on the page I was trying to reproduce with ASP.NET 2.0 was the following: Handwritten HTML imagemaps (no whitestrip between them): <table>
9
1644
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0's ImageMap Control to create 2 imagemaps, one directly below the other. When I do this a thin blank space appears between them. After several days of frustration I realized that the difference between what the ImageMap Control outputs and the html on the page I was trying to reproduce with ASP.NET 2.0 was the following: Handwritten HTML imagemaps (no whitestrip between them): <table>
1
2796
by: yusufjammy | last post by:
How to control parallel port with visual basic 2008 ? thanks in advance
0
8306
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
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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
8503
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
8605
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
6164
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
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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
2
1615
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.