473,395 Members | 1,631 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,395 software developers and data experts.

vb.net multithreading -

Ok
I have a multithreaded windows service application. This application
serves reports back to multiple web applications. This service can
run from 1-x reports (on different threads) at any given time. My
problem is once I start a thread running, if I need to abort the
thread, I don't know how to referance it?

My code:
Private Sub StartReportServer()
Try
' DIM MY LOCAL VARIABLES
......
' READ THE CONFIG FILE
.....
While IsRunning
'LOOP THROUGH THE ARRAY OF AVAILABLE THREADS YOU HAVE TO SERVICE
While c < threads
' CHECK TO SEE IF THIS THREAD IS RUNNING
If arThreadCnts(3, c) = 0 Then
'IF IT IS NOT RUNNING CHECK TO SEE IF THERE IS ANY
REPORTS WAITING BY POLLING THE QUEUE
dtReportToRun = cFunctions.polldb()
' IF THERE IS WORK TO BE DONE READ THE DATA
FROM THE REPORTQUEUE
.....
' IF THE REPORT TYPE IS ACCESS CREATE SNAPSHOT
If vOutputFileType = "MSACCESS" Then
Dim cAccessFunc As New AccessFunc()
'ADD A HANDLER TO CAPTURE DATA BACK
FROM THE THREAD
AddHandler cAccessFunc.ThreadDone,
AddressOf RptMSAThreadDone
Dim othread1 As New Thread(AddressOf
cAccessFunc.CAccessSnapShot)
' SET THE PROPERTIES OF THE CLASS
AND START NEW THREAD
.....
' START THREAD
othread1.start()
Else
'DO THE SAME FOR EXCEL
Dim cExcelFunc As New ExcelFunc()
End If
End If
Else
' CHECK STATUS OF REPORT TO SEE IF IT IS
TIMED OUT THEN ABORT THREAD
dtReportStatus = cFunctions.CheckRptStatus(
arQueues(x), CLng(arThreadCnts(3, c)))
If CStr(dtReportStatus.Rows(0).Item
("ProcessingState")) = "T" Then
***** HERE I WANT TO ABORT THE THREAD IF IT HAS BEEN SET
***** TO A STATUS OF T FROM THE FRONT END
End If
End If
c += 1
End While
c = 0
x += 2
End While
c = 0
x = 1
Thread.CurrentThread.Sleep(1000)
End While
End Try
End Sub
-----------------------------------------------------------
Nov 20 '05 #1
5 4961
Check out the Windows Service Sample Article under Code Samples on my website[1]. While it's in C#, it's primarily a description of
a pattern.

HTH,

ChrisG

[1]http://www.dotnetconsultant.com
Nov 20 '05 #2
Steven,

Again you have a problem with object references. You should maintain an
array or collection of thread objects. Adding a new thread to the
collection as you need them. This way you can reference them later and
issue the myArrays(i).Abort if need be...

Regards,
Dan
"Steven Thomas" <st******@gapac.com> wrote in message
news:61**************************@posting.google.c om...
Ok
I have a multithreaded windows service application. This application
serves reports back to multiple web applications. This service can
run from 1-x reports (on different threads) at any given time. My
problem is once I start a thread running, if I need to abort the
thread, I don't know how to referance it?

My code:
Private Sub StartReportServer()
Try
' DIM MY LOCAL VARIABLES
......
' READ THE CONFIG FILE
.....
While IsRunning
'LOOP THROUGH THE ARRAY OF AVAILABLE THREADS YOU HAVE TO SERVICE
While c < threads
' CHECK TO SEE IF THIS THREAD IS RUNNING
If arThreadCnts(3, c) = 0 Then
'IF IT IS NOT RUNNING CHECK TO SEE IF THERE IS ANY
REPORTS WAITING BY POLLING THE QUEUE
dtReportToRun = cFunctions.polldb()
' IF THERE IS WORK TO BE DONE READ THE DATA
FROM THE REPORTQUEUE
.....
' IF THE REPORT TYPE IS ACCESS CREATE SNAPSHOT
If vOutputFileType = "MSACCESS" Then
Dim cAccessFunc As New AccessFunc()
'ADD A HANDLER TO CAPTURE DATA BACK
FROM THE THREAD
AddHandler cAccessFunc.ThreadDone,
AddressOf RptMSAThreadDone
Dim othread1 As New Thread(AddressOf
cAccessFunc.CAccessSnapShot)
' SET THE PROPERTIES OF THE CLASS
AND START NEW THREAD
.....
' START THREAD
othread1.start()
Else
'DO THE SAME FOR EXCEL
Dim cExcelFunc As New ExcelFunc()
End If
End If
Else
' CHECK STATUS OF REPORT TO SEE IF IT IS
TIMED OUT THEN ABORT THREAD
dtReportStatus = cFunctions.CheckRptStatus(
arQueues(x), CLng(arThreadCnts(3, c)))
If CStr(dtReportStatus.Rows(0).Item
("ProcessingState")) = "T" Then
***** HERE I WANT TO ABORT THE THREAD IF IT HAS BEEN SET
***** TO A STATUS OF T FROM THE FRONT END
End If
End If
c += 1
End While
c = 0
x += 2
End While
c = 0
x = 1
Thread.CurrentThread.Sleep(1000)
End While
End Try
End Sub
-----------------------------------------------------------

Nov 20 '05 #3

Dan,
Thanks for the input, but I am not sure how to go about creating this
array of threads so I can referance them. After looking at my code
snippet, where would I make the change so I would have an array of
threads?

Thanks in advance for your help.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #4
Steven,
you could use an array or a collection below is some untested/pseudo code
but you will get the idea

Dim col() as New Collection

' your code is here

Dim othread1 As New Thread(AddressOf cAccessFunc.CAccessSnapShot)

col.Add ("WhatEverKeyYouWouldLikeToUse", othread1)

' the rest of your code
Now if you need to reference you rthread later to abort, you would:

Dim aThread as Thread = col.Item("WhatEverKeyYouWouldLikeToUse")

aThread.Abort()

"Steven Thomas" <st******@gapac.com> wrote in message
news:O0*************@TK2MSFTNGP10.phx.gbl...

Dan,
Thanks for the input, but I am not sure how to go about creating this
array of threads so I can referance them. After looking at my code
snippet, where would I make the change so I would have an array of
threads?

Thanks in advance for your help.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #5
On Thu, 3 Jun 2004 16:25:01 -0400, solex wrote:
Dim col() as New Collection


Just to point out a small typo in your code. This line creates an array of
collections. It should be:

Dim col as New Collection 'Note the lack of parentheses
--
Chris

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #6

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

Similar topics

1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
47
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
9
by: tommy | last post by:
hi, i have found a example for multithreading and asp.net http://www.fawcette.com/vsm/2002_11/magazine/features/chester/ i want to speed up my website ... if my website is starting, they...
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
55
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to...
5
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use...
2
by: Pradnya Patil | last post by:
hi , I am trying to draw ' html div-tag ' on the screen which will resemble a rectangle through vb.net code. I want it to be drawn faster...so I introduced multithreading using Threadpool. I...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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,...
0
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...

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.