473,699 Members | 3,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

To start a thread

How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.

Jun 27 '08 #1
9 1420
On May 15, 12:41 pm, juan <j...@discussio ns.microsoft.co mwrote:
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
Hi,
This could be a basic example to run a seperate thread:

Imports System.threadin g
Module Module1

Sub Main()
Dim mythread As New Thread(AddressO f threadrun)
mythread.Start( )
End Sub

Sub threadrun()
For x As Integer = 0 To 10
Console.WriteLi ne("this is a thread!")
Next
Console.ReadLin e()
End Sub

End Module
Also check out MSDN for more thread class methods / properties:
http://msdn.microsoft.com/en-us/libr...d_members.aspx
msdn.microsoft. com/en-us/library/ms951089.aspx
http://msdn.microsoft.com/en-us/libr...ng.thread.aspx

Thanks,

Onur Güzel
Jun 27 '08 #2
"juan" <ju**@discussio ns.microsoft.co mschrieb
How can I do to start a thread. I tried everything... but it had no
work. Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
Which of the many links handling this topic do you want us to post? ;-)
Have you already had a look in the threading topics in the VB and
Framework docs? If you have a specific problem, which is it?

(sry, can't send a link because the online MSDN lib TOC is all Italian
now!??!)
Armin

Jun 27 '08 #3
What have you tried ? What doesn't work ? I's no sue for us to give you some
code you already tried.

As starting itself is quite simple I believe this is something more subtle
that just starting the thread (you have a problem when updating the UI , do
you ?).

Depending on what you want to do you may want also to check the
BackgroundWorke r class...

--
Patrice

"juan" <ju**@discussio ns.microsoft.co ma écrit dans le message de groupe de
discussion : FE************* *************** **...icrosof t.com...
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
Jun 27 '08 #4
I think that the problem is that I need to associate one element (for play
music) to the thread ("t"), and I don't know how.
I have tried to give to "t.start()" an argument, but Visual Basic refuse it.
It is an error.
Any other solution?
Thanks.

"juan" wrote:
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
Jun 27 '08 #5
You technically can use a timer.

Start the timer enabled = false
set the interval to a second

the first line of the timer put timer.enabled = false

and the timer will run ' turn itself off ' but the sub finishes running.

What are you trying to do in the other thread?

Its a very dirty way of doing it, but it does do the trick.
I did that once, as i dont fully understand how to do threads on my own yet,
and ill come back and learn them as they come.

Miro

"juan" <ju**@discussio ns.microsoft.co mwrote in message
news:FE******** *************** ***********@mic rosoft.com...
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
Jun 27 '08 #6
And you play the sound file using which method ? What kind of file is this
(MIDI, WAV ?) In most cases it should be handled for you as playing a sound
asynchronously is what you want most of the time...

Try for example :
http://msdn.microsoft.com/en-us/library/cf1shcah.aspx

Note that the AudioPlayMode.B ackground option ("Plays the sound in the
background. The calling code continues to execute.").

It's best to always provide an description of what you are trying to do
rather than just how (in case someone would have another better/simpler way
to do the same thing).

--
Patrice

"juan" <ju**@discussio ns.microsoft.co ma écrit dans le message de groupe de
discussion : F0************* *************** **...icrosof t.com...
I think that the problem is that I need to associate one element (for play
music) to the thread ("t"), and I don't know how.
I have tried to give to "t.start()" an argument, but Visual Basic refuse
it.
It is an error.
Any other solution?
Thanks.

"juan" wrote:
>How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
Jun 27 '08 #7
On May 15, 10:29 am, juan <j...@discussio ns.microsoft.co mwrote:
I think that the problem is that I need to associate one element (for play
music) to the thread ("t"), and I don't know how.
I have tried to give to "t.start()" an argument, but Visual Basic refuse it.
It is an error.
Any other solution?
Thanks.

"juan" wrote:
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
First off, google about sending parameters to new threads, as of 2.0
you can do this without much trouble once you get used to the call
structure.

The other thing you could look at, which is now my personal favorite
for managing threads, is to create a delegate that I will use to
invoke a method asynchronously. I won't explain it here, you're sure
to find plenty of articles on it on the web which will explain it much
better than I would.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #8
Now I think that I have always had it. However the thread that plays music
seems to interrupt by the principal thread (the program thread). It is a
program for text processing.
Thanks in any case.

"juan" wrote:
I think that the problem is that I need to associate one element (for play
music) to the thread ("t"), and I don't know how.
I have tried to give to "t.start()" an argument, but Visual Basic refuse it.
It is an error.
Any other solution?
Thanks.

"juan" wrote:
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
Jun 27 '08 #9
On May 16, 5:07 am, juan <j...@discussio ns.microsoft.co mwrote:
Now I think that I have always had it. However the thread that plays music
seems to interrupt by the principal thread (the program thread). It is a
program for text processing.
Thanks in any case.

"juan" wrote:
I think that the problem is that I need to associate one element (for play
music) to the thread ("t"), and I don't know how.
I have tried to give to "t.start()" an argument, but Visual Basic refuse it.
It is an error.
Any other solution?
Thanks.
"juan" wrote:
How can I do to start a thread. I tried everything... but it had no work.
Any solution?
It is a Sub working with a Timer control.
I want to do two tasks at the same time (more or less for a minute).
Visual Basic 2005.
Thanks.
I have had very good luck with the following methods:
1) using a timer to start the action, it is messy but it does work.
Make sure you put the minimum amount of work in the timer process. I
have used timers to fire delegates so that a longer starting process
doesn't conflict with the timer.
2) If at all possible, use a discreet object for your separate thread.
3) To manage synchronization and scope, I have often passed a
reference to the controlling (dispatching) thread to the object that
will operate separately.
4) For managed communication you use delegates to raise events from
the child (free threaded) object which lets the free thread
communicate with the sender.
if you feel more brave:
5) It is very instructional to look at thread pooling (I use it for an
application I have writes application files for Progress and then
launches them maintaining 10-15 running instances at a time.) I
mention this as you indicate doing background processing.
6) Thread callbacks, even if you choose not to use them, are worth
understanding if you are going to adventure into the maddening world
of threading.

You may want to check out an erarlier post I had at
http://groups.google.com/group/micro...5acbf0ae15e871
for some code and links to MSDN explanations.

Hope this helps.
Viva la VB
Jun 27 '08 #10

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

Similar topics

0
1045
by: Phil | last post by:
I recently replaced my Toshiba 6100 laptop running XP Pro with a Dell Latitude D810 running XP Pro; since that time an application that I developed over a year ago has stopped working. I am using the same development environments, code, and third-party components. Nothing is different except the development computer. If I use my test app, written in C#, to "drive" the DLL, the thread starts and the program works flawlessly on the Dell. ...
16
4208
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the project in debug mode (by hitting F5) it gives an error message "Error while trying to run project: Unable to start debugging on the web server.
9
3205
by: Tim D | last post by:
Hi, I originally posted this as a reply to a rather old thread in dotnet.framework.general and didn't get any response. I thought it might be more relevant here; anyone got any ideas? My questions are below... "David Good" wrote: > We have a network running both Win2k and Win2k3 webservers and our web sites > reside on a UNC network share that happens to be a Network Appliance NAS.
3
1888
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this case it does gets all files from a directory. then i need to update the GUI with information from the thread... the thread should be started with a parameter, in this case its a string
5
2213
by: taylorjonl | last post by:
I am completely baffled. I am writting a daemon application for my work to save me some time. The application works fine at my home but won't work right here at work. Basically I have a MainForm what has a Start/Stop button that starts and stops the processing thread. private void StartButton_Click(object sender, System.EventArgs e) { if( bStopSignal ) { // disable controls that aren't valid when running
37
8893
by: ales | last post by:
Hello, I have a problem with creation of new thread. The method .Start() of newly created thread delays current thread for 0 - 1 second. Cpu while delay occurs is about 5%. Any idea? Here is code used for measuring:
5
4766
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a set of sensor data per second to a socket server. The socket server will do two things: 1. write data into a file via bsddb; 2. forward the data to a GUI written in wxpython. I am thinking the code should work as follow (not sure it is feasible)...
8
1696
by: Carl Heller | last post by:
If I'm creating a class to do some work that I want threaded out, where's the best location to call ThreadStart? Or does it depend on the nature of the work? a. Call it outside the class, giving it the starting method of the class? b. Have the class create the thread itself? ie: x = new WorkerClass(); ioThread = new Thread(new ThreadStart(x.StartWork));
0
2946
by: sauce | last post by:
Hi, Hm this error has gotten me really frustrated....I wrote a cgi script implementing threads using the threading module, but ran into these errors from my web server: Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib64/python2.3/threading.py", line 436, in __bootstrap self.run() File "test.py", line 214, in run current.start() File "/usr/lib64/python2.3/threading.py", line 410, in start...
0
1523
by: Yue Fei | last post by:
I have a multi thread python code, threads can start immediately if I run on command line, but I can get them started right the way if I call the same code from C/C++. test code like this: from threading import Thread import thread class testThread(Thread): def __init__ (self, id): Thread.__init__(self) self.id = id def run(self):
0
9187
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8936
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8894
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7776
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6540
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5879
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3071
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 we have to send another system
3
2015
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.