Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / April 2006

Tip: Looking for answers? Try searching our database.

Timer problem in CF 1.1 on WinCE 4.2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
hakan aktan - 01 Apr 2006 07:44 GMT
I have a timer and a few sequent function inside it. Functions are called
in a "For ..Each" code block.Program does not response any request that made
by form while code goes into timer. I used an "Application.DoEvents()" at
just beginning of timer.tick but i can not use it inside "For ..Each".
If  i do that program makes stg strange and stop working. How may i make my
program to response user in all these sequent events.Any advice would be
nice..
Thanx in advance..
Signature

Hakan Aktan
Software Developer

Daniel Moth - 01 Apr 2006 21:57 GMT
You have to explain your problem better by showing a code sample.

Even though I don't understand what issue you are facing here are two common
*mistakes* devs make when it comes to timers:
1. Specify a small interval for the timer. In a NETCF app anything under a
second for a Windows.Forms.Timer and you really have to question the reasons
behind it.
2. Leave the timer running without coding for reentrant conditions. In other
words, what you should be doing is starting your timer, stopping it when it
fires and then restarting it if you have to at the end of the timer_tick
handling code.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

> I have a timer and a few sequent function inside it. Functions are called
> in a "For ..Each" code block.Program does not response any request that
[quoted text clipped - 5 lines]
> be nice..
> Thanx in advance..
hakan aktan - 03 Apr 2006 07:08 GMT
Here some code from my code ( timer is form timer).I added explanations of
my problem inside code.
Thanx in advance.

Private Sub timerTank_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timerTank.Tick

'Application.DoEvents() works here but whern i use it inside FOR as below
program stops.

Application.DoEvents()

For counter = 0 To hashTableTank.Count - 1

'Here is the code (Just inside for) where i want to use Application.DoEvents
becuase when code runs here , form does not response requests.

   If portSettings() AndAlso portOpen() Then

   Select Case Trim(currentTankControl.probeType)

   Case "Cylindir"

CalculateCylindir()

   Case "Rectangle"

       CalcuateRectangle()

End Select

Else

MsgBox("Check Comm Ports.")

Exit Sub

End If

Next

End Sub

Note:  CalculateCylindir()  & CalcuateRectangle()   methods have a few
sleep like ( System.Threading.Thread.Sleep( 100 )  ) inside them.

Signature

Hakan Aktan
Software Developer

"Daniel Moth" <dmoth74@hotmail.com>, haber iletisinde þunlarý
yazdý:%23qVwe8cVGHA.5900@tk2msftngp13.phx.gbl...

> You have to explain your problem better by showing a code sample.
>
[quoted text clipped - 11 lines]
> Daniel
> --
Daniel Moth - 03 Apr 2006 09:15 GMT
So you are not addressing the two concerns I raised.
1. What is the interval of the timer?
2. I don't see you disabling the timer in timerTank_Tick (and if necessary
re-enabling it on exit)

Once you've done the second and verified that the answer to the first is
>1000 then we can proceed.

FYI, there are very few cases where DoEvents is justified and it is
sometimes an indication of code requiring worker threads (or some wrapper
like BackgroundWorker). This will certainly be the case here if your two
calculate methods are long running (which, btw, shouldn't have Sleep in them
since you are calling them on the UI thread)

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

> Here some code from my code ( timer is form timer).I added explanations of
> my problem inside code.
[quoted text clipped - 58 lines]
>> Daniel
>> --
<ctacke/> - 03 Apr 2006 14:00 GMT
Sure, the behavior you describe is expected.  The Forms.Timer handler runs
in the UI thread context.  While it's running, the UI won't service other
stuff, so it will appear locked.  Use a Threading.Timer.

-Chris

> Here some code from my code ( timer is form timer).I added explanations of
> my problem inside code.
[quoted text clipped - 58 lines]
>> Daniel
>> --
Dick Grier - 03 Apr 2006 18:32 GMT
It is seldom a good idea to call Application.DoEvents (though there are
exceptions).  You often can use a worker thread instead, and achieve better
performance.  I suggest threading only when needed, but  if your loop takes
seconds to run, then it may be a good idea.  However, if the loop completes
in a couple hundred mS, then don't bother... And, don't bother with
Application.DoEvents.

Signature

Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.

<ctacke/> - 02 Apr 2006 14:50 GMT
Is this a FOrms Timer or a Threading Timer?

-Chris

> I have a timer and a few sequent function inside it. Functions are called
> in a "For ..Each" code block.Program does not response any request that
[quoted text clipped - 5 lines]
> be nice..
> Thanx in advance..
Daniel Moth - 02 Apr 2006 15:05 GMT
He mentions "Tick" so I guess it's the Forms.Timer

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

> Is this a FOrms Timer or a Threading Timer?
>
[quoted text clipped - 9 lines]
>> be nice..
>> Thanx in advance..
<ctacke/> - 02 Apr 2006 18:29 GMT
And you know where guessing gets you...oh wait, that's assuming.  Same
principal anyway.

-Chris

> He mentions "Tick" so I guess it's the Forms.Timer
>
[quoted text clipped - 16 lines]
>>> be nice..
>>> Thanx in advance..
Daniel Moth - 02 Apr 2006 19:20 GMT
I presumed that guessing != assuming :-)

(and given that I am on the side of the pond that invented the language I've
got to be right, right?)

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

> And you know where guessing gets you...oh wait, that's assuming.  Same
> principal anyway.
[quoted text clipped - 21 lines]
>>>> would be nice..
>>>> Thanx in advance..

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.