473,656 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding ActiveX controls at runtime and threading

In short we have a lengthy process when a form is loaded that adds
activex controls to our windows form. This process in itself works
fine however we would like to push this processing to a thread but are
stumped so far.

Our goal is simply to allow the form to fully display while the
controls are being added. Preferrably with a progressbar to let them
know that the form is still being built.

Here are some snippets.

Private Sub Form_Shown(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Shown
Dim myThread As Threading.Threa d
myThread = New Threading.Threa d(AddressOf load_udfSection s)
myThread.SetApa rtmentState(Thr eading.Apartmen tState.STA)
myThread.Start( )
End Sub

Private Sub load_udfSection s()
...
udfSection = New AxTdF_DynamicUD F.AxDynUDF

udfSection.Begi nInit()
udfSection.Anch or =
CType(((System. Windows.Forms.A nchorStyles.Top Or
System.Windows. Forms.AnchorSty les.Left) _
Or System.Windows. Forms.AnchorSty les.Right),
System.Windows. Forms.AnchorSty les)
udfSection.Enab led = True
udfSection.Visi ble = False
udfSection.Loca tion = New
System.Drawing. Point(ToolStrip Container1.Cont entPanel.Margin .Left,
currentTop)
udfSection.Name = "AxDynUDF" & CStr(controlInd ex + 1)

With ToolStripContai ner1.ContentPan el
axWidth = .Width - (.Margin.Left + .Margin.Right)
End With

udfSection.Size = New System.Drawing. Size(axWidth, 1)

ToolStripContai ner1.ContentPan el.Invoke(New
addControl(Addr essOf addControlToToo lstrip), udfSection)
udfSection.EndI nit()

udfSection.load _Controls(CShor t(reader("Contr olGroupID")), True)

.....
End Sub
There is a delegate called addcontroltoToo lstrip for the following
function.

Private Sub addControlToToo lstrip(ByVal activexControl As
AxTdF_DynamicUD F.AxDynUDF)
ToolStripContai ner1.ContentPan el.Controls.Add (activexControl )
End Function

The invoke on the toolstrip seems to work fine but then when we try to
call endinit() it errors telling us that the control has been modified
in a different thread.

Any ideas? Only been using .NET for a week so there is no chance of
offending me. In VB6 we would have just started a timer in the show
event of the form which would let the event exit and then the timer
would process our lengthy code. Ugly but it at least allowed the form
to fully display before adding the remaining controls. Looking for
something a little bit more interactive.

Glenn Welker
Jun 26 '06 #1
3 2085
On Mon, 26 Jun 2006 08:47:53 -0400, Toe Dipper
<to*******@disc ussions.microso ft.com> wrote:
In short we have a lengthy process when a form is loaded that adds
activex controls to our windows form. This process in itself works
fine however we would like to push this processing to a thread but are
stumped so far.

Our goal is simply to allow the form to fully display while the
controls are being added. Preferrably with a progressbar to let them
know that the form is still being built.

Here are some snippets.

Private Sub Form_Shown(ByVa l sender As Object, ByVal e As
System.EventAr gs) Handles Me.Shown
Dim myThread As Threading.Threa d
myThread = New Threading.Threa d(AddressOf load_udfSection s)
myThread.SetApa rtmentState(Thr eading.Apartmen tState.STA)
myThread.Start( )
End Sub

Private Sub load_udfSection s()
...
udfSection = New AxTdF_DynamicUD F.AxDynUDF

udfSection.Begi nInit()
udfSection.Anch or =
CType(((System .Windows.Forms. AnchorStyles.To p Or
System.Windows .Forms.AnchorSt yles.Left) _
Or System.Windows. Forms.AnchorSty les.Right),
System.Windows .Forms.AnchorSt yles)
udfSection.Enab led = True
udfSection.Visi ble = False
udfSection.Loca tion = New
System.Drawing .Point(ToolStri pContainer1.Con tentPanel.Margi n.Left,
currentTop)
udfSection.Name = "AxDynUDF" & CStr(controlInd ex + 1)

With ToolStripContai ner1.ContentPan el
axWidth = .Width - (.Margin.Left + .Margin.Right)
End With

udfSection.Size = New System.Drawing. Size(axWidth, 1)

ToolStripContai ner1.ContentPan el.Invoke(New
addControl(Add ressOf addControlToToo lstrip), udfSection)
udfSection.EndI nit()

udfSection.load _Controls(CShor t(reader("Contr olGroupID")), True)

.....
End Sub
There is a delegate called addcontroltoToo lstrip for the following
function.

Private Sub addControlToToo lstrip(ByVal activexControl As
AxTdF_DynamicU DF.AxDynUDF)
ToolStripContai ner1.ContentPan el.Controls.Add (activexControl )
End Function

The invoke on the toolstrip seems to work fine but then when we try to
call endinit() it errors telling us that the control has been modified
in a different thread.

Any ideas? Only been using .NET for a week so there is no chance of
offending me. In VB6 we would have just started a timer in the show
event of the form which would let the event exit and then the timer
would process our lengthy code. Ugly but it at least allowed the form
to fully display before adding the remaining controls. Looking for
something a little bit more interactive.

Glenn Welker


Based on what you posted, you are essentially continuing what would
normally happen in the Load Event, so I'm not sure why you want to use
a separate thread to continue loading controls. Is there some other
background process going on that is not shown in your code?

In VB6, I used a similar concept which worked fine - show the main
form ASAP, then continue with the load event. In VB2005, my
experience, so far, hs been that this is a bit more difficult to
implement from app to app as, in some cases, the main form has a
tendency to do an undesirable repaint when adding and positioning
controls after the main form is visible particularly when I have code
in the Layout Event.

Gene

Jun 26 '06 #2

Based on what you posted, you are essentially continuing what would
normally happen in the Load Event, so I'm not sure why you want to use
a separate thread to continue loading controls. Is there some other
background process going on that is not shown in your code?

In VB6, I used a similar concept which worked fine - show the main
form ASAP, then continue with the load event. In VB2005, my
experience, so far, hs been that this is a bit more difficult to
implement from app to app as, in some cases, the main form has a
tendency to do an undesirable repaint when adding and positioning
controls after the main form is visible particularly when I have code
in the Layout Event.

Gene


We were really just trying to clean up a hack that has been in our
code too long.

You are right we are trying to continue the load event. The code I
have referenced takes up to 10 seconds. Without any progress
indication to the user, it appears that the form has locked up. It
seemed like I could load the controls in a background process while
updating a progress bar in the main thread. This would have enabled
the user to move the gui and get feedback on the progress while the
background process finished.

Our solution for VB6 seems to be less robust under vb 2005. Since the
documentation for doevents points to multithreading it seems possible,
although quite complicated.

I appreciate your feedback.
Jun 27 '06 #3
On Tue, 27 Jun 2006 09:13:18 -0400, Toe Dipper
<to*******@disc ussions.microso ft.com> wrote:

Based on what you posted, you are essentially continuing what would
normally happen in the Load Event, so I'm not sure why you want to use
a separate thread to continue loading controls. Is there some other
background process going on that is not shown in your code?

In VB6, I used a similar concept which worked fine - show the main
form ASAP, then continue with the load event. In VB2005, my
experience, so far, hs been that this is a bit more difficult to
implement from app to app as, in some cases, the main form has a
tendency to do an undesirable repaint when adding and positioning
controls after the main form is visible particularly when I have code
in the Layout Event.

Gene


We were really just trying to clean up a hack that has been in our
code too long.

You are right we are trying to continue the load event. The code I
have referenced takes up to 10 seconds. Without any progress
indication to the user, it appears that the form has locked up. It
seemed like I could load the controls in a background process while
updating a progress bar in the main thread. This would have enabled
the user to move the gui and get feedback on the progress while the
background process finished.

Our solution for VB6 seems to be less robust under vb 2005. Since the
documentatio n for doevents points to multithreading it seems possible,
although quite complicated.

I appreciate your feedback.


A common technique for a long load time (10 seconds is long) is to
display a sort of spash screen (not the VB2005 splash screen) as soon
as the main form is displayed where the splash form contains a label
that is updating iindicating to the user that there is activity.
PhotoShop is a good example if you are familiar with that program.

Gene
Jun 27 '06 #4

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

Similar topics

0
2755
by: don | last post by:
hello all, msdn says this about using a dotnet windows control library in activex environment... You have to write one relatively small piece of code to make your .NET control accessible to ActiveX hosts. ActiveX controls make several registry entries that standard COM servers don't, so you have to add this functionality to your .NET control. The CLR contains prefabricated functions that will make and remove these entries. These
1
1588
by: Andrew Chalk | last post by:
I have written an ActiveX component for a WEB app. that is invoked by an ASP page. Since multiple instances of this page will be requested, are there any special coding practises that I should be aware of? I ask this because it 'crashes' (CPU goes to 100%) after 'a few' hours runtime. Are separate instances of the control invoked with each new page request? Many thanks.
2
5859
by: Javier Bertran | last post by:
Hi all, I have an ActiveX control developed in Visual C++ 6.0 that I want to use in a C# project. I want the ActiveX code to run on a separate thread, but can't seem to get it to work. If for example my ActiveX member has an infinite loop, the .NET app gives all processing to the ActiveX and never returns, not even to redraw the window. Here is what I tried (in a nutshell): VC++ 6.0 OCX code: void CMyAXControlCtrl::Loop()
1
2613
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 me know the result. Regards
2
1998
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 from the web server to a printer on the user's network. The way it works today the user has to manually download each document and send it to his printer, but now they want me to create an automated process. Will I be able to download documents...
3
6853
by: Evan Delodder | last post by:
I am trying to edit form elements (labels, text box's, etc) in Visual Studio.NET using VB.NET. Whenever I edit certain forms’ appearance whether it is through the code, or through the designer, I receive this (Invalid ActiveX State Exception) error message at runtime whenever the form is called. I am simply trying to change the size and location of some form elements whose location and size were thrown off during the upgrade from VB6.0 to...
0
1040
by: Dan | last post by:
hI have a series of ActiveX controls written in VB6 that I want to now use in VB.NET. In the VB6 world I loaded these controls at runtime as needed. This worked great as they all implemented a common interface. I am having some issues now when I try to do the same things in VB.NET. The controls will load, however, they fail on the following line of code If TypeOf UserControl.Extender.Parent Is IControlInterface Then
7
4391
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 ActiveX controls that are to be used by a pda need to be written in the ..net compact framework, or am i missing something else here? i have a HP iPaq 2490 with Windows Mobile Premium installed While i'm at it; does a activex control allow you to...
4
6784
by: Wilfried Mestdagh | last post by:
Hi, I have a C# application (VS2005) with Microsoft Mappoint activeX control on a form. At a certain moment I want to create a second one temporary in code. This seems not to work, when I try to access it I have an InvalidActiveXState Exception. I cannot find mutch on the web about this Invalid State of a component except that it is invalid (what the Exception already describe). So I hope someone here knows ?
0
8382
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
8297
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
8717
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
8498
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
8600
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
6162
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
4150
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
1600
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.