|
-
Jan 23rd, 2011, 03:55 PM
#1
Thread Starter
Junior Member
Runing something in a different thread
Hey guys,
Sorry to bother you again but this time i was wondering how i can run whatever button_1 does in a different thread
Thanks in advance
-
Jan 23rd, 2011, 04:04 PM
#2
Re: Runing something in a different thread
Create a method, like a sub or function, process your code in it, and initiate it through the Thread class. You can view the documentation on MSDN here.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 04:27 PM
#3
Thread Starter
Junior Member
Re: Runing something in a different thread
hey um thanks for that but i am having a bit difficulties initiating it through the Thread class
-
Jan 23rd, 2011, 04:29 PM
#4
Re: Runing something in a different thread
 Originally Posted by Th3man
hey um thanks for that but i am having a bit difficulties initiating it through the Thread class
You have to help me help you. If it's not working, I need to know what's happening, what you're trying, any errors that occur, etc.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 04:33 PM
#5
Thread Starter
Junior Member
Re: Runing something in a different thread
well okay im making a test program where
button 1 code:
vb Code:
Dim SAPI SAPI = CreateObject("sapi.spvoice") SAPI.Speak(TextBox1.Text)
but when its reading the text i cant click my other button
button 2 code:
vb Code:
Dim SAPI SAPI = CreateObject("sapi.spvoice") SAPI.pause
so i want to make button 1 run on a different thread and i was wondering how to do that
-
Jan 23rd, 2011, 04:36 PM
#6
Re: Runing something in a different thread
That's the code that should be in the method. Where's the method you've created and the code for the thread?
That code should be in your method and thread code should be in the button. Did you even read the MSDN page? It even gives an example at the bottom.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 04:41 PM
#7
Thread Starter
Junior Member
Re: Runing something in a different thread
The method was
speak:
vb Code:
Dim SAPI SAPI = CreateObject("sapi.spvoice") SAPI.Speak(TextBox1.Text)
Thats how far i went i kkinda got confused after that,a nd i di read the page
-
Jan 23rd, 2011, 04:42 PM
#8
Re: Runing something in a different thread
And that code looks like VB6 code. You shouldn't be using that. You should be using the VB.NET code. Also, you need to turn on Option Strict. It will help prevent errors. If it were on, it would let you create an object without specifying its type.
VB.NET Code:
Imports System.Speech.Synthesis Dim speaker as New SpeechSynthesizer() speaker.Rate = 1 speaker.Volume = 100 speaker.Speak(TextBox1.Text)
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 04:44 PM
#9
Re: Runing something in a different thread
 Originally Posted by Th3man
The method was
speak:
vb Code:
Dim SAPI
SAPI = CreateObject("sapi.spvoice")
SAPI.Speak(TextBox1.Text)
Thats how far i went i kkinda got confused after that,a nd i di read the page 
That's not a method. I already told you what a method is. It's a sub or function. In this case, you just want to create a sub, place the code in the sub and then call the sub through the thread via AddressOf. Just read the page. If you're confused, then ask what whatever you're confused about means and I'll answer it. But, like I said, it gives you an example at the bottom of the page.
I'm not going to give you the answer. You have to put in the work and igure it out. I'm just leading you to it.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 04:47 PM
#10
Re: Runing something in a different thread
Also, I should point out that you can use a BackgroundWorker to do this, but I personally hate using that method.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 04:53 PM
#11
Thread Starter
Junior Member
Re: Runing something in a different thread
so in button1 i would initiate the thread class ?
so the code would be
Option Explicit ON
Imports System
Imports System.Threading
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
Dim t As New Thread(AddressOf speak)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button2.Click
Dim SAPI
SAPI = CreateObject("sapi.spvoice")
sapi.pause()
End Sub
Private Sub speak
Dim SAPI
SAPI = CreateObject("sapi.spvoice")
SAPI.Speak(TextBox1.Text)
t.sleep()
End Sub
End Class
Thats how far i am
-
Jan 23rd, 2011, 04:56 PM
#12
Re: Runing something in a different thread
So, other than the old and outdated code, you're almost there.
Basically, you've lined up your racers, but you haven't told them to Start.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 04:58 PM
#13
Thread Starter
Junior Member
Re: Runing something in a different thread
Where would i ask threading to start?
-
Jan 23rd, 2011, 05:00 PM
#14
Re: Runing something in a different thread
 Originally Posted by Th3man
Where would i ask threading to start?
By calling start on the thread variable you created. Please for the love of Bob, look at the example on the MSDN site I linked.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jan 23rd, 2011, 05:09 PM
#15
Thread Starter
Junior Member
Re: Runing something in a different thread
I read it and still cant get it may you please just show me an example just this one time
-
Jan 23rd, 2011, 05:21 PM
#16
Re: Runing something in a different thread
you won't get far in your programming career without learning how to get around the msdn documentation... it's right there where he linked: http://msdn.microsoft.com/en-us/library/6x4c42hc.aspx
shows exactly how to start a thread you just declared. he even told you NOT to use VB6 code, yet post #11 shows you threw that suggestion to the wind.
-
Jan 25th, 2011, 05:45 PM
#17
Thread Starter
Junior Member
Re: Runing something in a different thread
I learn from examples and if you guys are just gonna not help the way that helps me the most is okay. Im not trying to disrepect but yea right now...
-
Jan 25th, 2011, 06:13 PM
#18
Re: Runing something in a different thread
well there's an example on the msdn page.
-
Jan 25th, 2011, 10:12 PM
#19
Hyperactive Member
Re: Runing something in a different thread
@TH3man
You need to start a thread after you specify it
vb Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
Dim t as Thread
t = New Thread(AddressOf speak)
t.Start
End Sub
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|