473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ActiveX User Control

Dan
Good Day All,

I am having a problem in Visual Studio 2005 Beta 2. I am hoping someone
might have an idea as to what is going on.

I have an ActiveX User Control written using Visual Basic 6.0. Using Visual
Studio 2005 I add the control to my Toolbox. I then drag the control onto a
Panel control that is on a form. That is it. I don't write any code at all.
When I run the program I get the following error:

Cross-thread operation not valid: Control 'Panel1' accessed from a thread
other than the thread it was created on
The error appears right away and the form is never rendered to the screen.
This happens if I try creating the Windows Form project in either VB.NET or
C#.NET. However, if I follow the same steps in Visual C++.NET then the
application will start and the form will show up like it is suppose to.

I am confused by this. There has to be something going on under the hood
that allows C++ to handle this when the other languages don't. If anyone has
any ideas I would appreciate it.
Thanks!

Dan DeLuca

Nov 17 '05 #1
5 2610

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
Good Day All,

I am having a problem in Visual Studio 2005 Beta 2. I am hoping someone
might have an idea as to what is going on.

I have an ActiveX User Control written using Visual Basic 6.0. Using
Visual
Studio 2005 I add the control to my Toolbox. I then drag the control onto
a
Panel control that is on a form. That is it. I don't write any code at
all.
When I run the program I get the following error:

Cross-thread operation not valid: Control 'Panel1' accessed from a thread
other than the thread it was created on
The error appears right away and the form is never rendered to the screen.
This happens if I try creating the Windows Form project in either VB.NET
or
C#.NET. However, if I follow the same steps in Visual C++.NET then the
application will start and the form will show up like it is suppose to.

I am confused by this. There has to be something going on under the hood
that allows C++ to handle this when the other languages don't. If anyone
has
any ideas I would appreciate it.
Thanks!

Dan DeLuca


Your code or the ActiveX control's code are accessing the UI from another
thread than the UI thread. This is not allowed in windows, v2.0 has a debug
probe that signals this (wrong) behavior when running in the debugger.
Make sure:
1. you don't create the ActiveX control object from another thread (guess
you don't)
2. you have your Main attributed with [STAThread].

Willy.
Nov 17 '05 #2
Dan,

Just curious, on the entry point to your application, do you have the
STAThread attribute on the Main method? You will need this for Windows
Forms applications, especially ones using ActiveX controls. If it is not
there, then the program is in the multi-threaded apartment, which is a no-no
for ActiveX controls.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:CF**********************************@microsof t.com...
Good Day All,

I am having a problem in Visual Studio 2005 Beta 2. I am hoping someone
might have an idea as to what is going on.

I have an ActiveX User Control written using Visual Basic 6.0. Using
Visual
Studio 2005 I add the control to my Toolbox. I then drag the control onto
a
Panel control that is on a form. That is it. I don't write any code at
all.
When I run the program I get the following error:

Cross-thread operation not valid: Control 'Panel1' accessed from a thread
other than the thread it was created on
The error appears right away and the form is never rendered to the screen.
This happens if I try creating the Windows Form project in either VB.NET
or
C#.NET. However, if I follow the same steps in Visual C++.NET then the
application will start and the form will show up like it is suppose to.

I am confused by this. There has to be something going on under the hood
that allows C++ to handle this when the other languages don't. If anyone
has
any ideas I would appreciate it.
Thanks!

Dan DeLuca

Nov 17 '05 #3
Dan
Willy and Nicholas,

Thanks for responding to my post so quickly. I appreciate it.

I looked at the C#, VB.NET, and C++ versions of the project. All three had
the STAThread attribute applied to the main method. Despite this I still get
the error on the C# and VB.NET versions but not on the C++ version.

Do you have any other ideas as to how I can deal with this or what can be
causing it? I did check the Active X control and made sure that it was also
set to Single Thread.

Thanks!

Dan DeLuca
Nov 17 '05 #4

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
Willy and Nicholas,

Thanks for responding to my post so quickly. I appreciate it.

I looked at the C#, VB.NET, and C++ versions of the project. All three had
the STAThread attribute applied to the main method. Despite this I still
get
the error on the C# and VB.NET versions but not on the C++ version.

Do you have any other ideas as to how I can deal with this or what can be
causing it? I did check the Active X control and made sure that it was
also
set to Single Thread.

Thanks!

Dan DeLuca


What do you mean with "single thread", you really don't mean ThreadingModel
= "Single" in the registry.
If that's true you have to rebuild the control as "Apartment" threaded, and
you should never ever build Single threaded controls to be used in 32 bit
windows applications. These COM objects live on a OLE created/managed thread
and not the Main UI thread, that would explain the cross-thread failure
message.

Willy.
PS. Is the C++ application a managed application? Guess not, so the probe
isn't used.

Nov 17 '05 #5
Dan
Willy,

If you lived in Omaha I would buy you a beer. That was the problem. The
ActiveX control was set to Single and not Apartment. As soon as I changed
that it worked just fine.

Thank you so much for taking the time to help me through this issue. You
have saved me countless hours of head scratching and I really appreciate it.

Dan
Nov 17 '05 #6

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

Similar topics

2
by: Fie Fie Niles | last post by:
This one XP machine (with IE 6) is having a problem viewing any ActiveX controls (created on VB6) on the Internet Explorer browser. I put the same ActiveX control in a VB program, and when I run...
4
by: SiuLoBow | last post by:
Hi, Is there anyway to detect the ActiveX control is able to run on the browser or not? After I installed the ActiveX control to my system, user sometimes switch the secruity setting to "not...
4
by: blacst | last post by:
I am using Access 2002 with either Service Pack 1 or 3. (I have seen this problem on 4 different OSs (NT, XP Home, XP Pro, Winows 2000) across 8 different machines) I have an ActiveX Object...
1
by: Sreejumon [MVP] | last post by:
Hi, If you want to use the activex controls in your asp.net page, you ahev to use the single aprtment thread model. For that please add the "aspcompat=true" attribute the page directive. Let...
5
by: Andrew | last post by:
Hi all, I am still getting into ASP/VB.net and have a concern about something I see coming. Currently our entire website is classic ASP, yet the feelings from on high is that we need to start...
1
by: Anand Kale | last post by:
How to have ActiveX control called from Web Form in ASP.Net ? ActiveX control is written using VC++/MFC/ATL-COM. Also kindly answer following issues, 1. Also how to take care of issues about...
3
by: Jeffery Franzen | last post by:
Anyone know where the documentation is regarding Activex controls in asp web forms? I'm using VS.NET 2002 enterprise and am trying to use Activex controls in vb.net web form app. I do the add...
2
by: Shawn | last post by:
Hi. I've never created an ActiveX control before, so I know little about what it is capable of and what its limitations are. My problem is this: I have to create a way to send multiple documents...
7
by: Jarod_24 | last post by:
I just downloaded a activex control that was written in C# and tried to view it on my PDA's Internet Explorer. At my regular PC it displayed just fine, but nothing showed up on the pda. Do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.