473,396 Members | 1,940 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.

Multi Threading and VB.Net

28
hi..

i am fairly new to VB.Net and I have a form thats calling a crystal report. The report however takes a long time to load. i tried using Threads and I keep getting the following error : [ controls created on one thread cannot be parented to a control on another thread ] how can i solve this error. Any assistance is greatly appreciated

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.     Public docReport As New rptStatus
  4.     Public invReport As New rptInventory
  5.     Public useReport As New rptUser
  6.     Public oReport As Object
  7.     Public rType as String
  8.  
  9.  
  10.   Private Sub frmReports_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  11.  
  12.         If rType = "Inventory" Then
  13.             oReport = invReport
  14.         ElseIf rType = "Status" Then
  15.             oReport = docReport
  16.         Else
  17.             oReport = useReport
  18.             oReport.SetParameterValue(0, param3)
  19.             oReport.SetParameterValue(1, param4)
  20.             oReport.SetParameterValue(2, param1)
  21.             oReport.SetParameterValue(3, param2)
  22.         End If
  23.  
  24.         Dim repThread As New Thread(AddressOf loadReport)
  25.         repThread.IsBackground = True
  26.         repThread.Priority = ThreadPriority.Normal
  27.         repThread.Start()
  28.  
  29.     End Sub
  30.  
  31.  
  32.  
  33.  Private Sub loadReport()
  34.  
  35.         Control.CheckForIllegalCrossThreadCalls = False
  36.         cviewer.Visible = True
  37.         Me.Cursor = Cursors.WaitCursor
  38.         frmMain.tslCurrent.Text = "Loading Report ..."
  39.         Application.DoEvents()
  40.  
  41.         Try
  42.             Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
  43.             Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
  44.  
  45.             For Each myTable In oReport.Database.Tables
  46.                 myLogin = myTable.LogOnInfo
  47.                 myLogin.ConnectionInfo.Password = strPass
  48.                 myLogin.ConnectionInfo.UserID = strUser
  49.                 myLogin.ConnectionInfo.ServerName = strServer
  50.                 myLogin.ConnectionInfo.DatabaseName = strDatabase
  51.                 myTable.ApplyLogOnInfo(myLogin)
  52.             Next
  53.  
  54.  
  55.             '******************ERROR OCCURS HERE *******************************
  56.             cviewer.ReportSource = oReport
  57.             cviewer.ShowRefreshButton = False
  58.  
  59.         Catch ex As Exception
  60.  
  61.             MsgBox(ex.Message)
  62.             frmMain.tslCurrent.Text = "Report not Loaded"
  63.  
  64.         Finally
  65.             Me.Cursor = Cursors.Default
  66.             'frmMain.tslCurrent.Text = ""
  67.         End Try
  68.     End Sub
  69.  
  70.  
  71.  
Jul 21 '08 #1
2 2154
jhaxo
57
In windows you can't access a gui element from any thread except the ui thread. Microsoft has provided something called delegates that your thread can invoke on the gui thread. A delegate is an object that can point to a function.

Here is a tutorial
http://www.codeproject.com/KB/vb/Delegate.aspx

I looked for one on this site. I am sure there is one but I didn't see it.

The basic idea is every Form has a method BeginInvoke so you need to :

1. Define a delegate
Expand|Select|Wrap|Line Numbers
  1. public delegate void MyDelegate(string mssg); //in c#.
2. instantiate a delegate
Expand|Select|Wrap|Line Numbers
  1. MyDelegate mydelegate = new ShowStatusDelegate(myfunction)
3. define the function pointed to by the delegate
Expand|Select|Wrap|Line Numbers
  1. void myfunction(string txt)
  2. {
  3.    textbox1.Text=txt;
  4. }
4. now in your thread:
Expand|Select|Wrap|Line Numbers
  1. BeginInvoke(mydelegate,new object[]{"hello delegate world");
Jul 21 '08 #2
richkid
28
hi..
thanks for that post.... I tried it and I am now getting the report to show.. only problem is that Im back at the original problem because now I have to wait on the report to load before I can do anything :(
Jul 22 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
0
by: Stuart Norris | last post by:
Dear Group, I am attempting to write a "splash" and "status" Form using a second thread. I wish to use this Form to display status information to the user when I do CPU intensive work in my...
13
by: notregister | last post by:
my program have as many as 8 threads running at a same time. can different threads open a same file at the same time? let say thread1 open a file abc.txt at the same time with thread 2, both doing...
2
by: NiponW | last post by:
Hi, I have SQL SERVER 2000 SP4 Enterprise , Windows 2003 Enterprise on Xeon 4 Processors (now with multi-threading CPU) and I have questions which seem weirds to me (used to have the same...
20
by: dotyet | last post by:
Hi Everyone, It would be a real big help if anyone can shed light on whether DB2 UDB 8.2 on Solaris will make optimum use of a Sun T2000 server. The server has 1 CPU with 8 cores and each core...
0
ammoos
by: ammoos | last post by:
hi friends pls help me.. i got an assignment which i feel very difficult to me.. i dont have more knowledge about multi-threading in .net... the assignment details is below.... pls help me... i...
14
by: Akihiro KAYAMA | last post by:
Hi all. I found cooperative multi-threading(only one thread runs at once, explicit thread switching) is useful for writing some simulators. With it, I'm able to be free from annoying mutual...
5
by: George Maicovschi | last post by:
As multi-threading is not built in PHP I've been using a hack letting the Apache server handle the multi-threading issues, but I'm really curious of other approaches to this issue. If anyone has...
1
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
Sorry this is so long winded, but here goes. Following the model of http://msdn2.microsoft.com/en-us/library/system.runtime.remoting.channels.ipc.ipcchannel.aspx I made a remote object using the...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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,...

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.