473,508 Members | 4,324 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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shown
Dim myThread As Threading.Thread
myThread = New Threading.Thread(AddressOf load_udfSections)
myThread.SetApartmentState(Threading.ApartmentStat e.STA)
myThread.Start()
End Sub

Private Sub load_udfSections()
...
udfSection = New AxTdF_DynamicUDF.AxDynUDF

udfSection.BeginInit()
udfSection.Anchor =
CType(((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
udfSection.Enabled = True
udfSection.Visible = False
udfSection.Location = New
System.Drawing.Point(ToolStripContainer1.ContentPa nel.Margin.Left,
currentTop)
udfSection.Name = "AxDynUDF" & CStr(controlIndex + 1)

With ToolStripContainer1.ContentPanel
axWidth = .Width - (.Margin.Left + .Margin.Right)
End With

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

ToolStripContainer1.ContentPanel.Invoke(New
addControl(AddressOf addControlToToolstrip), udfSection)
udfSection.EndInit()

udfSection.load_Controls(CShort(reader("ControlGro upID")), True)

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

Private Sub addControlToToolstrip(ByVal activexControl As
AxTdF_DynamicUDF.AxDynUDF)
ToolStripContainer1.ContentPanel.Controls.Add(acti vexControl)
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 2063
On Mon, 26 Jun 2006 08:47:53 -0400, Toe Dipper
<to*******@discussions.microsoft.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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Shown
Dim myThread As Threading.Thread
myThread = New Threading.Thread(AddressOf load_udfSections)
myThread.SetApartmentState(Threading.ApartmentStat e.STA)
myThread.Start()
End Sub

Private Sub load_udfSections()
...
udfSection = New AxTdF_DynamicUDF.AxDynUDF

udfSection.BeginInit()
udfSection.Anchor =
CType(((System.Windows.Forms.AnchorStyles.Top Or
System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right),
System.Windows.Forms.AnchorStyles)
udfSection.Enabled = True
udfSection.Visible = False
udfSection.Location = New
System.Drawing.Point(ToolStripContainer1.ContentP anel.Margin.Left,
currentTop)
udfSection.Name = "AxDynUDF" & CStr(controlIndex + 1)

With ToolStripContainer1.ContentPanel
axWidth = .Width - (.Margin.Left + .Margin.Right)
End With

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

ToolStripContainer1.ContentPanel.Invoke(New
addControl(AddressOf addControlToToolstrip), udfSection)
udfSection.EndInit()

udfSection.load_Controls(CShort(reader("ControlGro upID")), True)

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

Private Sub addControlToToolstrip(ByVal activexControl As
AxTdF_DynamicUDF.AxDynUDF)
ToolStripContainer1.ContentPanel.Controls.Add(acti vexControl)
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*******@discussions.microsoft.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
documentation 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
2738
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...
1
1579
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...
2
5842
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...
1
2602
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...
2
1990
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...
3
6838
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...
0
1035
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...
7
4379
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...
4
6778
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...
0
7128
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
7332
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,...
1
7058
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
7502
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...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4715
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...
0
3206
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...
0
1565
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 ...
0
426
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...

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.