473,581 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class wth Thread

Hello

I have a problem with thread i have a class defntion i've create but every
time i call it from thread it's null any idea why?

code:

dim test as class1

test.a=1
test.b=2
test.c =3
Dim t As Thread

t = New Thread(AddressO f Me.DoIt)

t.Start()

sub doit()

dim a = test.a ' i get null

end sub

Public Class Class1

Public a As Integer

Public b As Integer

Public c As Integer

End Class
Jun 24 '07 #1
9 1090

"nondos" <no****@nondos. orgwrote in message
news:GM******** *************** *******@giganew s.com...
Hello

I have a problem with thread i have a class defntion i've create but every
time i call it from thread it's null any idea why?

code:

dim test as class1

test.a=1
test.b=2
test.c =3
Dim t As Thread

t = New Thread(AddressO f Me.DoIt)

t.Start()

sub doit()

dim a = test.a ' i get null

end sub
Public Shared Class Class1

Public Shared a As Integer

Public Shared b As Integer

Public Shared c As Integer

End Class


Then you can use Class1.a = test.a

Use Goggle or go to the VS Help and look-up the *Shared* keyword and find
out what it does.

Either you have to instantiate class1 with Dim class1 = new class1 at some
point or you use the Shared keyword.

It should have not compiled or blew up IMHO. I don't know how you got away
with it. You must have Option Strict turned off for the project.

Jun 24 '07 #2
"nondos" <no****@nondos. orgschrieb
Hello

I have a problem with thread i have a class defntion i've create but
every time i call it from thread it's null any idea why?

You did not assign an object to variable test. Use "new" to do that:

code:

dim test as class1

test = new class1

test.a=1
test.b=2
test.c =3
Dim t As Thread

t = New Thread(AddressO f Me.DoIt)

t.Start()

sub doit()

dim a = test.a ' i get null

end sub

Public Class Class1

Public a As Integer

Public b As Integer

Public c As Integer

End Class

Armin
Jun 24 '07 #3
Hi mr Arnold,

Can you tell us why option strict should be off. At least (I am sure of)
both Armin and I are very interested in that.

Cor
"Mr. Arnold" <MR. Ar****@Arnold.c omschreef in bericht
news:uA******** ******@TK2MSFTN GP05.phx.gbl...
>
"nondos" <no****@nondos. orgwrote in message
news:GM******** *************** *******@giganew s.com...
>Hello

I have a problem with thread i have a class defntion i've create but
every time i call it from thread it's null any idea why?

code:

dim test as class1

test.a=1
test.b=2
test.c =3
Dim t As Thread

t = New Thread(AddressO f Me.DoIt)

t.Start()

sub doit()

dim a = test.a ' i get null

end sub
>Public Shared Class Class1

Public Shared a As Integer

Public Shared b As Integer

Public Shared c As Integer

End Class



Then you can use Class1.a = test.a

Use Goggle or go to the VS Help and look-up the *Shared* keyword and find
out what it does.

Either you have to instantiate class1 with Dim class1 = new class1 at some
point or you use the Shared keyword.

It should have not compiled or blew up IMHO. I don't know how you got away
with it. You must have Option Strict turned off for the project.

Jun 24 '07 #4

"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
Hi mr Arnold,

Can you tell us why option strict should be off. At least (I am sure of)
both Armin and I are very interested in that.
I don't know ask the OP. The OP is the one that has the problem. :)

Jun 24 '07 #5
I don't know ask the OP. The OP is the one that has the problem. :)

Lol :-)

Well i guess the OP has a special sort of compiler

"Mr. Arnold" <MR. Ar****@Arnold.c omschreef in bericht
news:eC******** *******@TK2MSFT NGP04.phx.gbl.. .
>
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>Hi mr Arnold,

Can you tell us why option strict should be off. At least (I am sure of)
both Armin and I are very interested in that.

I don't know ask the OP. The OP is the one that has the problem. :)

Jun 24 '07 #6
Cor Ligthert [MVP] wrote:
Hi mr Arnold,

Can you tell us why option strict should be off. At least (I am sure of)
both Armin and I are very interested in that.

Cor
I must have been off, otherwise there would have been a compiling error.
That doesn't mean that it should be off.

--
Göran Andersson
_____
http://www.guffa.com
Jun 24 '07 #7

Cor,
With option strict ON

the provided code would raise 2 errors

option strict requires all variabels to have an as clause
name Test is not declared ( as it is method scoped )

so it wouldn`t even compile

if run with option strict off it would also not compile because of some
coding errors

However this could run ( although not my prog style ) in this way
>>>This works
Imports System.Threadin g
Public Class Form1
Private test As New Class1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
test.a = 1
test.b = 2
test.c = 3
Dim t As Thread

t = New Thread(AddressO f Me.doit)

t.Start()
End Sub
Sub doit()

Dim a As Integer = test.a ' now you get 1 :-)

End Sub

End Class
Public Class Class1
Public a As Integer
Public b As Integer
Public c As Integer
End Class



"Cor Ligthert [MVP]" wrote:
Hi mr Arnold,

Can you tell us why option strict should be off. At least (I am sure of)
both Armin and I are very interested in that.

Cor
"Mr. Arnold" <MR. Ar****@Arnold.c omschreef in bericht
news:uA******** ******@TK2MSFTN GP05.phx.gbl...

"nondos" <no****@nondos. orgwrote in message
news:GM******** *************** *******@giganew s.com...
Hello

I have a problem with thread i have a class defntion i've create but
every time i call it from thread it's null any idea why?

code:

dim test as class1

test.a=1
test.b=2
test.c =3
Dim t As Thread

t = New Thread(AddressO f Me.DoIt)

t.Start()

sub doit()

dim a = test.a ' i get null

end sub
Public Shared Class Class1

Public Shared a As Integer

Public Shared b As Integer

Public Shared c As Integer

End Class


Then you can use Class1.a = test.a

Use Goggle or go to the VS Help and look-up the *Shared* keyword and find
out what it does.

Either you have to instantiate class1 with Dim class1 = new class1 at some
point or you use the Shared keyword.

It should have not compiled or blew up IMHO. I don't know how you got away
with it. You must have Option Strict turned off for the project.


Jun 25 '07 #8
Michel,

I have had big fights with Armin about Option Strict, I found it very easy
to set it off, luckily it was as far as I remember me the only real
discussion with Armin. Now I think it is almost possible to cast to the
right object. (Even if that is casting over a cast).

Armin is one of the oldest members of this newsgroup, however it is normal
that he is doing nothing for almost a year and than begins again very
intensive.

Cor
Jun 25 '07 #9
correction
Almost "forever" possible
-------------------------------

"Cor Ligthert [MVP]" <no************ @planet.nlschre ef in bericht
news:eo******** ******@TK2MSFTN GP04.phx.gbl...
Michel,

I have had big fights with Armin about Option Strict, I found it very easy
to set it off, luckily it was as far as I remember me the only real
discussion with Armin. Now I think it is almost possible to cast to the
right object. (Even if that is casting over a cast).

Armin is one of the oldest members of this newsgroup, however it is normal
that he is doing nothing for almost a year and than begins again very
intensive.

Cor


Jun 26 '07 #10

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

Similar topics

2
1991
by: Rudi | last post by:
Is there anyone who can point me to a good tutorial on how to create a multithreaded class library? Class A is a controller that starts up a number of threads of code in Class B. Class B raises events back to Class A. I want the code in the eventhandlers of Class A to run on the thread that created the object. In a Windows.Forms control...
4
1544
by: Daylor | last post by:
hi. i have multi thread application in vb.net is there a way NET support, so i can mark the class , to be access only for 1 thread each time ? if there is , small sytax sample will help //what i need to add , so only 1 thread per time can access this class in MultiThread app.
6
1901
by: Vladislav Kosev | last post by:
I have this strange problem now twice: I am writing this relatevely large web site on 2.0 and I made a static class, which I use for url encoding and deconding (for remapping purposes). This static class needs the session context to encode a url (because I stored the current language there), so I made a static field of type HttpContext, which...
4
6210
by: jayesah | last post by:
Hi All, I am writting a Thread class with using pthread library. I have some problem in saving thread function type and argument type. How to make Thread class generic ? /* This is my global Function */ template < class FunType, class ArgType> Thread makeThread(Funtype fun, ArgType arg)
3
1891
by: TamusJRoyce | last post by:
Hello. This is my first thread here. My problem has probably been came across by a lot of people, but tutorials and things I've seen don't address it (usually too basic). My problem is that I would like to use Abstraction for a "plug-in" like interface to classes. class ThreadHandle { /* stuff here not yet dealing with threads */
0
7792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8149
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. ...
0
8304
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7899
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...
0
8175
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...
0
5364
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...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1403
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1138
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...

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.