473,378 Members | 1,334 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,378 software developers and data experts.

Threading logical problem??

What I want to implement is to restart certain thread every 24 hours...

sample code:

Dim T() As Thread
Dim L() As Lib1.Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim i As Integer = 0
For i = 0 To 2

ReDim Preserve T(i)
ReDim Preserve L(i)

L(i) = New Lib1.Class1
L(i).m1 = i

T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()

Trace.WriteLine(T(i).ThreadState.ToString) '<---- Unstarted ??
Next

End Sub



Nov 20 '05 #1
8 1022
"James A Taber" <ic*******@hotmail.com> schrieb
What I want to implement is to restart certain thread every 24
hours...

sample code:

[...]
Trace.WriteLine(T(i).ThreadState.ToString) '<----
Unstarted ??
As long as *this* thread runs, the other one might still be unstarted, but
the OS will start it when it is it's turn.
Next

End Sub


Maybe I did not understand the problem, yet. Isn't starting a
System.Timers.Timer sufficient?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Hi Armin,

Thanks for you reply,

The timer works fine... what I am experiencing is that somtimes some of the
thread seams to stop working ... thats why I want to restart all the threads
in the application after a certain time....

-James A Taber


"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"James A Taber" <ic*******@hotmail.com> schrieb
What I want to implement is to restart certain thread every 24
hours...

sample code:

[...]
Trace.WriteLine(T(i).ThreadState.ToString) '<----
Unstarted ??


As long as *this* thread runs, the other one might still be unstarted, but
the OS will start it when it is it's turn.
Next

End Sub


Maybe I did not understand the problem, yet. Isn't starting a
System.Timers.Timer sufficient?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
James,
In addition to Armin's comments, have you tried using Thread.Sleep(0) to
give the second thread a chance to start?

Something like:
T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()
Thread.Sleep(0)

Trace.WriteLine(T(i).ThreadState.ToString) '<---- Unstarted ??
Its not that your second thread did not start as much as your first thread
is not sharing the CPU. ;-)

Also in addition to restarting threads, you may want to consider restarting
AppDomains also.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl... What I want to implement is to restart certain thread every 24 hours...

sample code:

Dim T() As Thread
Dim L() As Lib1.Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim i As Integer = 0
For i = 0 To 2

ReDim Preserve T(i)
ReDim Preserve L(i)

L(i) = New Lib1.Class1
L(i).m1 = i

T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()

Trace.WriteLine(T(i).ThreadState.ToString) '<---- Unstarted ??
Next

End Sub


Nov 20 '05 #4
Hi Jay,

I have tried use Sleep(3000) but it didnt make any difference ... is it
possible that the timer in Class1 one is running in its own thread?

hm... restart Appdomain ? how can I do that ?

is this true --> Restart Appdomain = Initialize Application

James A Taber
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
James,
In addition to Armin's comments, have you tried using Thread.Sleep(0) to
give the second thread a chance to start?

Something like:
T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()
Thread.Sleep(0)

Trace.WriteLine(T(i).ThreadState.ToString) '<---- Unstarted ??
Its not that your second thread did not start as much as your first thread
is not sharing the CPU. ;-)

Also in addition to restarting threads, you may want to consider restarting AppDomains also.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
What I want to implement is to restart certain thread every 24 hours...

sample code:

Dim T() As Thread
Dim L() As Lib1.Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim i As Integer = 0
For i = 0 To 2

ReDim Preserve T(i)
ReDim Preserve L(i)

L(i) = New Lib1.Class1
L(i).m1 = i

T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()

Trace.WriteLine(T(i).ThreadState.ToString) '<---- Unstarted

?? Next

End Sub



Nov 20 '05 #5
James,
is it
possible that the timer in Class1 one is running in its own thread? Hard to say as you don't say what type of timer is in Class1. Remember there
are 3 distinct Timer classes in .NET.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl... Hi Jay,

I have tried use Sleep(3000) but it didnt make any difference ... is it
possible that the timer in Class1 one is running in its own thread?

hm... restart Appdomain ? how can I do that ?

is this true --> Restart Appdomain = Initialize Application

James A Taber
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
James,
In addition to Armin's comments, have you tried using Thread.Sleep(0) to
give the second thread a chance to start?

Something like:
T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()
Thread.Sleep(0)

Trace.WriteLine(T(i).ThreadState.ToString) '<---- Unstarted ??

Its not that your second thread did not start as much as your first thread
is not sharing the CPU. ;-)

Also in addition to restarting threads, you may want to consider restarting
AppDomains also.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
What I want to implement is to restart certain thread every 24

hours...
sample code:

Dim T() As Thread
Dim L() As Lib1.Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim i As Integer = 0
For i = 0 To 2

ReDim Preserve T(i)
ReDim Preserve L(i)

L(i) = New Lib1.Class1
L(i).m1 = i

T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()

Trace.WriteLine(T(i).ThreadState.ToString) '<----

Unstarted ?? Next

End Sub




Nov 20 '05 #6
James,
Yes restarting an AppDomain is effectively the same as re-initializing your
app, however you can control what parts of your app are running in which
AppDomain.

I don't have a clean example, to "restart" an AppDomain, you need to create
a new AppDomain and start execution there, letting the current one finish. I
would start by looking at the System.AppDomain class and its Load & Unload
methods...

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
Hi Jay,

I have tried use Sleep(3000) but it didnt make any difference ... is it
possible that the timer in Class1 one is running in its own thread?

hm... restart Appdomain ? how can I do that ?

is this true --> Restart Appdomain = Initialize Application

James A Taber
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:es**************@TK2MSFTNGP10.phx.gbl...
James,
In addition to Armin's comments, have you tried using Thread.Sleep(0) to
give the second thread a chance to start?

Something like:
T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()
Thread.Sleep(0)

Trace.WriteLine(T(i).ThreadState.ToString) '<---- Unstarted ??

Its not that your second thread did not start as much as your first thread
is not sharing the CPU. ;-)

Also in addition to restarting threads, you may want to consider restarting
AppDomains also.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
What I want to implement is to restart certain thread every 24

hours...
sample code:

Dim T() As Thread
Dim L() As Lib1.Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim i As Integer = 0
For i = 0 To 2

ReDim Preserve T(i)
ReDim Preserve L(i)

L(i) = New Lib1.Class1
L(i).m1 = i

T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1
contains a timer to do the required task.
T(i).Start()

Trace.WriteLine(T(i).ThreadState.ToString) '<----

Unstarted ?? Next

End Sub




Nov 20 '05 #7
Thanks for helping me out Jay...

This is the Timer iam using

System.Timers.Timer

I will look more into the Appdomain "feature" later tonigh...

Thanks again
-James A Taber
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uN**************@TK2MSFTNGP10.phx.gbl...
James,
is it
possible that the timer in Class1 one is running in its own thread? Hard to say as you don't say what type of timer is in Class1. Remember

there are 3 distinct Timer classes in .NET.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
Hi Jay,

I have tried use Sleep(3000) but it didnt make any difference ... is it
possible that the timer in Class1 one is running in its own thread?

hm... restart Appdomain ? how can I do that ?

is this true --> Restart Appdomain = Initialize Application

James A Taber
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:es**************@TK2MSFTNGP10.phx.gbl...
James,
In addition to Armin's comments, have you tried using Thread.Sleep(0) to give the second thread a chance to start?

Something like:
> T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1 > contains a timer to do the required task.
> T(i).Start()

Thread.Sleep(0)

>
> Trace.WriteLine(T(i).ThreadState.ToString) '<----

Unstarted
??

Its not that your second thread did not start as much as your first

thread is not sharing the CPU. ;-)

Also in addition to restarting threads, you may want to consider

restarting
AppDomains also.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
> What I want to implement is to restart certain thread every 24 hours... >
> sample code:
>
> Dim T() As Thread
> Dim L() As Lib1.Class1
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click
>
> Dim i As Integer = 0
> For i = 0 To 2
>
> ReDim Preserve T(i)
> ReDim Preserve L(i)
>
> L(i) = New Lib1.Class1
> L(i).m1 = i
>
> T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1 > contains a timer to do the required task.
> T(i).Start()
>
> Trace.WriteLine(T(i).ThreadState.ToString) '<----

Unstarted
??
> Next
>
> End Sub
>
>
>
>
>
>
>



Nov 20 '05 #8
James,
System.Timers.Timer will raise its event in a new thread (via the
ThreadPool), there is no need to create a thread to explicitly handle it.

For details on the Timers.Timer and the other 2 timers in .NET check out
this recent article:

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Thanks for helping me out Jay...

This is the Timer iam using

System.Timers.Timer

I will look more into the Appdomain "feature" later tonigh...

Thanks again
-James A Taber
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uN**************@TK2MSFTNGP10.phx.gbl...
James,
is it
possible that the timer in Class1 one is running in its own thread? Hard to say as you don't say what type of timer is in Class1. Remember

there
are 3 distinct Timer classes in .NET.

Hope this helps
Jay

"James A Taber" <ic*******@hotmail.com> wrote in message
news:us**************@tk2msftngp13.phx.gbl...
Hi Jay,

I have tried use Sleep(3000) but it didnt make any difference ... is it possible that the timer in Class1 one is running in its own thread?

hm... restart Appdomain ? how can I do that ?

is this true --> Restart Appdomain = Initialize Application

James A Taber
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:es**************@TK2MSFTNGP10.phx.gbl...
> James,
> In addition to Armin's comments, have you tried using
Thread.Sleep(0) to > give the second thread a chance to start?
>
> Something like:
> > T(i) = New Thread(AddressOf L(i).StartTimer) '<--- Class1 > > contains a timer to do the required task.
> > T(i).Start()
>
> Thread.Sleep(0)
>
> >
> > Trace.WriteLine(T(i).ThreadState.ToString) '<----

Unstarted
??
>
> Its not that your second thread did not start as much as your first

thread
> is not sharing the CPU. ;-)
>
> Also in addition to restarting threads, you may want to consider
restarting
> AppDomains also.
>
> Hope this helps
> Jay
>
> "James A Taber" <ic*******@hotmail.com> wrote in message
> news:e3**************@TK2MSFTNGP12.phx.gbl...
> > What I want to implement is to restart certain thread every 24

hours...
> >
> > sample code:
> >
> > Dim T() As Thread
> > Dim L() As Lib1.Class1
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e
As
> > System.EventArgs) Handles Button1.Click
> >
> > Dim i As Integer = 0
> > For i = 0 To 2
> >
> > ReDim Preserve T(i)
> > ReDim Preserve L(i)
> >
> > L(i) = New Lib1.Class1
> > L(i).m1 = i
> >
> > T(i) = New Thread(AddressOf L(i).StartTimer) '<---

Class1 > > contains a timer to do the required task.
> > T(i).Start()
> >
> > Trace.WriteLine(T(i).ThreadState.ToString) '<----

Unstarted
??
> > Next
> >
> > End Sub
> >
> >
> >
> >
> >
> >
> >
>
>



Nov 20 '05 #9

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

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
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...
8
by: [Yosi] | last post by:
I create new thread as following: Thread mThread = new Thread(new ThreadStart(m_ClassThread.Go)); In my system I have 2 Process devices ,(CPU0 and CPU1) , I want to create 3 Threads, 2 of those...
8
by: cj | last post by:
I need more information to read about threading in Visual Basic. Hopefully something linear w/o too many links to get lost in. I've been to...
11
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found...
15
by: WXS | last post by:
When I see things in .NET 2.0 like obsoletion of suspend/resume because of the public reason MS gives of they think people are using them inappropriately.. use mutex, monitor and other...
14
by: Simon Verona | last post by:
I think I'm doing this wrong : I have a class with a public shared method such as follows: public shared sub myFunction dim frm as new myFrm dim t as new Threading.Thread(Addressof ...
2
by: gwoodhouse | last post by:
Hello all, I have an application at the moment which uses forms. The main form (which has ALOT of things going on it in) also happens to do alot of network proccess's which ive put in Threads. ...
8
by: Frankie | last post by:
Just getting my feet wet with threading... Is it the case that... once a method starts executing in a given thread, that method will finish executing on that same thread? Or is it possible for...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.