Hi,

I want a know if is possible launch a separeted thread that run with a
interval of time like a Timer object (Timer.Tick).

my goal is put to buttons (Start and Stop), when user click Start i want
launch a thread that do something with a interval of 30 seconds at least,
but user can work normaly, but when user click Stop i want also stop thread.


--
Armando Rocha
Mobile Developer

http://www.ifthensoftware.com
PORTUGAL

Re: Threads help by Paul

Paul
Fri Jun 20 11:00:11 CDT 2008

Seems like we've had this discussion in this group before. Have you checked
the archives?

The pattern goes something like this:

-----

// This event will be set when you want the thread to exit.
protected AutoResetEvent thev = new AutoResetEvent( false );

startbutton_click()
{
th = new Thread( new ThreadStart( this.MyThread ) );
th.Start();
}

protected virtual void AcqThread()
{
while (thev.WaitOne(time, false) == false)
{
}

// The event was set. Time to exit the thread...
}

stopbutton_click()
{
thev.Set();

th.Join(waittime);
}

-----

Paul T.

"Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
news:38439AF5-A90E-4D39-9877-011CCA196E7E@microsoft.com...
> Hi,
>
> I want a know if is possible launch a separeted thread that run with a
> interval of time like a Timer object (Timer.Tick).
>
> my goal is put to buttons (Start and Stop), when user click Start i want
> launch a thread that do something with a interval of 30 seconds at least,
> but user can work normaly, but when user click Stop i want also stop
> thread.
>
>
> --
> Armando Rocha
> Mobile Developer
>
> http://www.ifthensoftware.com
> PORTUGAL



Re: Threads help by Paul

Paul
Fri Jun 20 11:07:44 CDT 2008

That's what happens when you copy/paste bits and pieces, but not the whole
program... Substitute the pieces below in your thinking:

-----

protected virtual void MyThread() // Helps to set the name right!
{
while (thev.WaitOne(time, false) == false)
{
// Do whatever processing you need here. This code will be executed
every 'time'
// milliseconds. So, if you want it to happen every 30s, set time
to 30000.
}

// The event was set. Time to exit the thread...
}

----

Note that you should *always* indicate what version of .NET CF you're
talking about. The code has to be written a *lot* differently for .NET CF
1.0 and 3.5...

Paul T.


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:ugcE26u0IHA.4220@TK2MSFTNGP02.phx.gbl...
> Seems like we've had this discussion in this group before. Have you
> checked the archives?
>
> The pattern goes something like this:
>
> -----
>
> // This event will be set when you want the thread to exit.
> protected AutoResetEvent thev = new AutoResetEvent( false );
>
> startbutton_click()
> {
> th = new Thread( new ThreadStart( this.MyThread ) );
> th.Start();
> }
>
> protected virtual void AcqThread()
> {
> while (thev.WaitOne(time, false) == false)
> {
> }
>
> // The event was set. Time to exit the thread...
> }
>
> stopbutton_click()
> {
> thev.Set();
>
> th.Join(waittime);
> }
>
> -----
>
> Paul T.
>
> "Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
> news:38439AF5-A90E-4D39-9877-011CCA196E7E@microsoft.com...
>> Hi,
>>
>> I want a know if is possible launch a separeted thread that run with a
>> interval of time like a Timer object (Timer.Tick).
>>
>> my goal is put to buttons (Start and Stop), when user click Start i want
>> launch a thread that do something with a interval of 30 seconds at least,
>> but user can work normaly, but when user click Stop i want also stop
>> thread.
>>
>>
>> --
>> Armando Rocha
>> Mobile Developer
>>
>> http://www.ifthensoftware.com
>> PORTUGAL
>
>



Re: Threads help by Armando

Armando
Fri Jun 20 11:12:06 CDT 2008

hi,

No, i never put this discussionin this group.

Thanks for the help Paul.

--
Armando Rocha
Mobile Developer

http://www.ifthensoftware.com
PORTUGAL
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> escreveu na mensagem news:ugcE26u0IHA.4220@TK2MSFTNGP02.phx.gbl...
> Seems like we've had this discussion in this group before. Have you
> checked the archives?
>
> The pattern goes something like this:
>
> -----
>
> // This event will be set when you want the thread to exit.
> protected AutoResetEvent thev = new AutoResetEvent( false );
>
> startbutton_click()
> {
> th = new Thread( new ThreadStart( this.MyThread ) );
> th.Start();
> }
>
> protected virtual void AcqThread()
> {
> while (thev.WaitOne(time, false) == false)
> {
> }
>
> // The event was set. Time to exit the thread...
> }
>
> stopbutton_click()
> {
> thev.Set();
>
> th.Join(waittime);
> }
>
> -----
>
> Paul T.
>
> "Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
> news:38439AF5-A90E-4D39-9877-011CCA196E7E@microsoft.com...
>> Hi,
>>
>> I want a know if is possible launch a separeted thread that run with a
>> interval of time like a Timer object (Timer.Tick).
>>
>> my goal is put to buttons (Start and Stop), when user click Start i want
>> launch a thread that do something with a interval of 30 seconds at least,
>> but user can work normaly, but when user click Stop i want also stop
>> thread.
>>
>>
>> --
>> Armando Rocha
>> Mobile Developer
>>
>> http://www.ifthensoftware.com
>> PORTUGAL
>
>


Re: Threads help by Paul

Paul
Fri Jun 20 11:21:16 CDT 2008

I don't mean you and I, personally. The archives of the group contain a
wealth of information, if you don't treat the group as a chat and, instead,
look to the archives *before* asking a question.

Paul T.

"Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
news:ea6bW$u0IHA.2208@TK2MSFTNGP04.phx.gbl...
> hi,
>
> No, i never put this discussionin this group.
>
> Thanks for the help Paul.
>
> --
> Armando Rocha
> Mobile Developer
>
> http://www.ifthensoftware.com
> PORTUGAL
> "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
> com> escreveu na mensagem news:ugcE26u0IHA.4220@TK2MSFTNGP02.phx.gbl...
>> Seems like we've had this discussion in this group before. Have you
>> checked the archives?
>>
>> The pattern goes something like this:
>>
>> -----
>>
>> // This event will be set when you want the thread to exit.
>> protected AutoResetEvent thev = new AutoResetEvent( false );
>>
>> startbutton_click()
>> {
>> th = new Thread( new ThreadStart( this.MyThread ) );
>> th.Start();
>> }
>>
>> protected virtual void AcqThread()
>> {
>> while (thev.WaitOne(time, false) == false)
>> {
>> }
>>
>> // The event was set. Time to exit the thread...
>> }
>>
>> stopbutton_click()
>> {
>> thev.Set();
>>
>> th.Join(waittime);
>> }
>>
>> -----
>>
>> Paul T.
>>
>> "Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
>> news:38439AF5-A90E-4D39-9877-011CCA196E7E@microsoft.com...
>>> Hi,
>>>
>>> I want a know if is possible launch a separeted thread that run with a
>>> interval of time like a Timer object (Timer.Tick).
>>>
>>> my goal is put to buttons (Start and Stop), when user click Start i want
>>> launch a thread that do something with a interval of 30 seconds at
>>> least, but user can work normaly, but when user click Stop i want also
>>> stop thread.
>>>
>>>
>>> --
>>> Armando Rocha
>>> Mobile Developer
>>>
>>> http://www.ifthensoftware.com
>>> PORTUGAL
>>
>>
>



Re: Threads help by Armando

Armando
Fri Jun 20 11:33:18 CDT 2008

you are right, bui i try find information for this issues but i cant find,
only after this i put my question to group.

--
Armando Rocha
Mobile Developer

http://www.ifthensoftware.com
PORTUGAL
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> escreveu na mensagem news:esZfnGv0IHA.5300@TK2MSFTNGP06.phx.gbl...
>I don't mean you and I, personally. The archives of the group contain a
>wealth of information, if you don't treat the group as a chat and, instead,
>look to the archives *before* asking a question.
>
> Paul T.
>
> "Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
> news:ea6bW$u0IHA.2208@TK2MSFTNGP04.phx.gbl...
>> hi,
>>
>> No, i never put this discussionin this group.
>>
>> Thanks for the help Paul.
>>
>> --
>> Armando Rocha
>> Mobile Developer
>>
>> http://www.ifthensoftware.com
>> PORTUGAL
>> "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
>> DOT com> escreveu na mensagem
>> news:ugcE26u0IHA.4220@TK2MSFTNGP02.phx.gbl...
>>> Seems like we've had this discussion in this group before. Have you
>>> checked the archives?
>>>
>>> The pattern goes something like this:
>>>
>>> -----
>>>
>>> // This event will be set when you want the thread to exit.
>>> protected AutoResetEvent thev = new AutoResetEvent( false );
>>>
>>> startbutton_click()
>>> {
>>> th = new Thread( new ThreadStart( this.MyThread ) );
>>> th.Start();
>>> }
>>>
>>> protected virtual void AcqThread()
>>> {
>>> while (thev.WaitOne(time, false) == false)
>>> {
>>> }
>>>
>>> // The event was set. Time to exit the thread...
>>> }
>>>
>>> stopbutton_click()
>>> {
>>> thev.Set();
>>>
>>> th.Join(waittime);
>>> }
>>>
>>> -----
>>>
>>> Paul T.
>>>
>>> "Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
>>> news:38439AF5-A90E-4D39-9877-011CCA196E7E@microsoft.com...
>>>> Hi,
>>>>
>>>> I want a know if is possible launch a separeted thread that run with a
>>>> interval of time like a Timer object (Timer.Tick).
>>>>
>>>> my goal is put to buttons (Start and Stop), when user click Start i
>>>> want launch a thread that do something with a interval of 30 seconds at
>>>> least, but user can work normaly, but when user click Stop i want also
>>>> stop thread.
>>>>
>>>>
>>>> --
>>>> Armando Rocha
>>>> Mobile Developer
>>>>
>>>> http://www.ifthensoftware.com
>>>> PORTUGAL
>>>
>>>
>>
>
>


Re: Threads help by Paul

Paul
Fri Jun 20 11:45:23 CDT 2008

What did you search on?! "thread periodic" gives great results...

Paul T.

"Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
news:38023134-F77F-4A84-A0A7-1EA8E795EF1C@microsoft.com...
> you are right, bui i try find information for this issues but i cant find,
> only after this i put my question to group.
>
> --
> Armando Rocha
> Mobile Developer
>
> http://www.ifthensoftware.com
> PORTUGAL
> "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
> com> escreveu na mensagem news:esZfnGv0IHA.5300@TK2MSFTNGP06.phx.gbl...
>>I don't mean you and I, personally. The archives of the group contain a
>>wealth of information, if you don't treat the group as a chat and,
>>instead, look to the archives *before* asking a question.
>>
>> Paul T.
>>
>> "Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
>> news:ea6bW$u0IHA.2208@TK2MSFTNGP04.phx.gbl...
>>> hi,
>>>
>>> No, i never put this discussionin this group.
>>>
>>> Thanks for the help Paul.
>>>
>>> --
>>> Armando Rocha
>>> Mobile Developer
>>>
>>> http://www.ifthensoftware.com
>>> PORTUGAL
>>> "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam
>>> DOT com> escreveu na mensagem
>>> news:ugcE26u0IHA.4220@TK2MSFTNGP02.phx.gbl...
>>>> Seems like we've had this discussion in this group before. Have you
>>>> checked the archives?
>>>>
>>>> The pattern goes something like this:
>>>>
>>>> -----
>>>>
>>>> // This event will be set when you want the thread to exit.
>>>> protected AutoResetEvent thev = new AutoResetEvent( false );
>>>>
>>>> startbutton_click()
>>>> {
>>>> th = new Thread( new ThreadStart( this.MyThread ) );
>>>> th.Start();
>>>> }
>>>>
>>>> protected virtual void AcqThread()
>>>> {
>>>> while (thev.WaitOne(time, false) == false)
>>>> {
>>>> }
>>>>
>>>> // The event was set. Time to exit the thread...
>>>> }
>>>>
>>>> stopbutton_click()
>>>> {
>>>> thev.Set();
>>>>
>>>> th.Join(waittime);
>>>> }
>>>>
>>>> -----
>>>>
>>>> Paul T.
>>>>
>>>> "Armando Rocha" <armandorocha@ifthensoftware.com> wrote in message
>>>> news:38439AF5-A90E-4D39-9877-011CCA196E7E@microsoft.com...
>>>>> Hi,
>>>>>
>>>>> I want a know if is possible launch a separeted thread that run with a
>>>>> interval of time like a Timer object (Timer.Tick).
>>>>>
>>>>> my goal is put to buttons (Start and Stop), when user click Start i
>>>>> want launch a thread that do something with a interval of 30 seconds
>>>>> at least, but user can work normaly, but when user click Stop i want
>>>>> also stop thread.
>>>>>
>>>>>
>>>>> --
>>>>> Armando Rocha
>>>>> Mobile Developer
>>>>>
>>>>> http://www.ifthensoftware.com
>>>>> PORTUGAL
>>>>
>>>>
>>>
>>
>>
>



RE: Threads help by srhartone

srhartone
Fri Jun 20 13:40:00 CDT 2008

Why can't you use the Threading.Timer class? this will execute on a separate
thread which essentially adds the request to the thread pool for you
automagically.
--
Simon Hart
Visual Developer - Device Application Development MVP
http://simonrhart.blogspot.com


"Armando Rocha" wrote:

> Hi,
>
> I want a know if is possible launch a separeted thread that run with a
> interval of time like a Timer object (Timer.Tick).
>
> my goal is put to buttons (Start and Stop), when user click Start i want
> launch a thread that do something with a interval of 30 seconds at least,
> but user can work normaly, but when user click Stop i want also stop thread.
>
>
> --
> Armando Rocha
> Mobile Developer
>
> http://www.ifthensoftware.com
> PORTUGAL
>

Re: Threads help by Scott

Scott
Fri Jun 20 14:05:15 CDT 2008

"Armando Rocha" <armandorocha@ifthensoftware.com> writes:

> I want a know if is possible launch a separeted thread that run with a
> interval of time like a Timer object (Timer.Tick).
>
> my goal is put to buttons (Start and Stop), when user click Start i
> want launch a thread that do something with a interval of 30 seconds
> at least, but user can work normaly, but when user click Stop i want
> also stop thread.

I would simply create a timer for this, and have the timer event
create a background thread and go off and do its work. Then the
Start/Stop button would just Enable/Disable the timer.

Depending on exactly what you need to do, it may not work for you, but
it works for my situation.

----Scott.

Re: Threads help by bpbrox

bpbrox
Fri Jun 20 14:18:46 CDT 2008

Armando Rocha skrev:
> Hi,
>
> I want a know if is possible launch a separeted thread that run with a
> interval of time like a Timer object (Timer.Tick).
>
> my goal is put to buttons (Start and Stop), when user click Start i want
> launch a thread that do something with a interval of 30 seconds at
> least, but user can work normaly, but when user click Stop i want also
> stop thread.
>
>
Here are some good tutorials:

http://msdn.microsoft.com/en-us/library/ms951109.aspx
http://www.yoda.arachsys.com/csharp/threads/

--
Bjørn Brox