Implement Threading in VB.net

abhisaber
 
on Oct 30, 2012 11:49 PM
4008 Views

I want to implement threading in VB.net. Here I want to use ThreadPool.QueueUserWorkItem() method.

Example:

ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf TaskA), AIsDone)


My Code:

ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf CType(tempControl, ReportletBase).GetReportData), Nothing)


Code block:

Try
                    'Load the ascx control within the TD cell
                    tempControl = Me.LoadControl("~/Reportlets/" & CStr(reportlet.id) & ".ascx")

           ---->   ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf CType(tempControl, ReportletBase).GetReportData), Nothing)

                    CType(tempControl, ReportletBase).Position = position
                    CType(tempControl, ReportletBase).ReportToBeLoadedIn = m_proxy.Report
                    reportlePlaceholder.Controls.AddAt(reportlePlaceholder.Controls.Count, tempControl)

 Catch ex As System.Exception


Description:

tempControl: variable holding references of user controls of type ReportletBase (base Class)

GetReportData(): It is main method in each user control class that inherits ReportletBase class. We want to implement multi-thread
on this method

Problem/Error:

Method 'Public MustOverride Function GetReportData() As System.Collections.Hashtable' does not have a signature compatible with delegate 'Delegate Sub WaitCallback(state As Object)'.

Here GetReportData() has return type as Hashtable - How to embedd this with delegate use in above code


 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Mudassar
 
on Oct 30, 2012 11:50 PM

Refer

http://www.dotnetperls.com/threadpool-vbnet

abhisaber
 
on Oct 31, 2012 04:09 AM

Hi Mudassar,

I already seen this article. however my requirement is bit different.

I have asyn the particular method i.e. GetReportData() of Type ReportletBase and its return is Hashtable.

 

How to achieve this.

Mudassar
 
on Oct 31, 2012 08:23 AM

So what you want to return?