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

Threading so restricted?

Hi all,

Is it honestly true we can't start threads in VB.net 2005 if the sub or
function has paratemeters like functioname(x1 as string, x2 as long) etc?

This so restricts launching new threads.

Global variables the only option?

We can't use TLS before launching the thread right?

Thanks a lot,
Adam
May 6 '06 #1
4 1122
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Is it honestly true we can't start threads in VB.net 2005 if the sub or
function has paratemeters like functioname(x1 as string, x2 as long) etc?


Check out the 'ParameterizedThreadStart' delegate.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
May 6 '06 #2
Adam,
This so restricts launching new threads.

Global variables the only option?


I don't think it's a big restriction. A common solution is to
encapsulate the thread logic in a separate class, pass the "thread
arguments" to a class constructor and store them in fields. No global
variables needed.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
May 6 '06 #3
Hmmm, looking at some code this only seems to be doable if the sub is in a
class.

Can't see anything if the sub is in a module,

Adam

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
Is it honestly true we can't start threads in VB.net 2005 if the sub or
function has paratemeters like functioname(x1 as string, x2 as long) etc?


Check out the 'ParameterizedThreadStart' delegate.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

May 6 '06 #4
Adam,
| Hmmm, looking at some code this only seems to be doable if the sub is in a
| class.
Look again, the target of a Delegate can be in a Module, Structure, or a
Class. It can also be a shared method of a Class or Structure.

For example:

Public Module MainModule

Private Sub Work(ByVal obj As Object)
Dim parameter As String = TryCast(obj, String)
... do stuff based on parameter ...
End Sub

Public Sub Main()
Dim worker As New Thread(AddressOf work)
Dim parameter As String = "Something"
worker.Start(parameter)
... wait for thread to finish ...
End Sub

End Module

Notice that the sub is in a Module. If I needed to pass more then one
parameter, I would consider passing a structure or a class...

NOTE: 'ParameterizedThreadStart' is new to .NET 2.0 (VS 2005)

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> wrote in message
news:OW**************@TK2MSFTNGP03.phx.gbl...
| Hmmm, looking at some code this only seems to be doable if the sub is in a
| class.
|
| Can't see anything if the sub is in a module,
|
| Adam
|
| "Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
| news:%2****************@TK2MSFTNGP03.phx.gbl...
| > "Adam Honek" <Ad*******@Webmaster2001.freeserve.co.uk> schrieb:
| >> Is it honestly true we can't start threads in VB.net 2005 if the sub or
| >> function has paratemeters like functioname(x1 as string, x2 as long)
etc?
| >
| > Check out the 'ParameterizedThreadStart' delegate.
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
May 8 '06 #5

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

Similar topics

30
by: Sean R. Lynch | last post by:
I've been playing around with Zope's RestrictedPython, and I think I'm on the way to making the modifications necessary to create a capabilities-based restricted execution system. The idea is to...
1
by: Gernot Hillier | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi! I'm the developer of a Linux ISDN application which uses embedded Python for controlling the communication. It starts several threads (i.e....
2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
13
by: Rolf Magnus | last post by:
Hi, I would like to embed a python interpreter within a program, but since that program would be able to automatically download scripts from the internet, I'd like to run those in a restricted...
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...
5
by: Peter Ammon | last post by:
It's my understanding that the printf() function is declared as int printf(const char * restrict format, ...); in stdio.h. And loosely speaking, if a parameter is declared as restricted, then...
10
by: Janto Dreijer | last post by:
I have been having problems with the Python 2.4 and 2.5 interpreters on both Linux and Windows crashing on me. Unfortunately it's rather complex code and difficult to pin down the source. So...
9
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this...
3
by: Paul Rudin | last post by:
I'm occasionally seeing tracebacks like this: Traceback (most recent call last): File "logging/__init__.py", line 744, in emit File "logging/__init__.py", line 630, in format File...
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...
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
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
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...
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.