473,473 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Create 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(AddressOf 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 1085

"nondos" <no****@nondos.orgwrote in message
news:GM******************************@giganews.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(AddressOf 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(AddressOf 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.comschreef in bericht
news:uA**************@TK2MSFTNGP05.phx.gbl...
>
"nondos" <no****@nondos.orgwrote in message
news:GM******************************@giganews.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(AddressOf 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****************@TK2MSFTNGP05.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.comschreef in bericht
news:eC***************@TK2MSFTNGP04.phx.gbl...
>
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP05.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.Threading
Public Class Form1
Private test As New Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
test.a = 1
test.b = 2
test.c = 3
Dim t As Thread

t = New Thread(AddressOf 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.comschreef in bericht
news:uA**************@TK2MSFTNGP05.phx.gbl...

"nondos" <no****@nondos.orgwrote in message
news:GM******************************@giganews.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(AddressOf 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.nlschreef in bericht
news:eo**************@TK2MSFTNGP04.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
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...
4
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 ...
6
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...
4
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...
3
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...
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...
1
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...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.