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 / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

running threads

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
garther - 19 Mar 2008 17:32 GMT
Hi

I'm writing an application which basically takes images from pixelink
camera and does some calculations on them.

I need to monitor the status of the system for 2 things: presence of
camera and connection to SQL server.

I also have a preview feature.

Right now it's all being done by a two timers (one for preview and
second for status) which run threads for status/preview.

On a decent Core 2 duo everything is quite smooth but on single core CPU
responsiveness of the application is not so good (sometimes main form is
frozen for couple of seconds).

How should i do those 2 processes so that they don't have an impact on
application performance?

Thx for any info!
Peter Ritchie [C# MVP] - 19 Mar 2008 17:41 GMT
What type of Timer are you using?  If it's Windows.Forms.Timer you're not
using a background thread.

Maybe you can provide some detailed code of what you're doing in your
Tick/Elapsed event handlers?

Signature

Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#

> Hi
>
[quoted text clipped - 17 lines]
>
> Thx for any info!
garther - 19 Mar 2008 18:12 GMT
In the timer i'm running a thread

---
Thread Status = new Thread(statusJob);
Status.Start():
----

Peter Ritchie [C# MVP] pisze:
> What type of Timer are you using?  If it's Windows.Forms.Timer you're not
> using a background thread.
>
> Maybe you can provide some detailed code of what you're doing in your
> Tick/Elapsed event handlers?
Peter Duniho - 19 Mar 2008 19:00 GMT
> In the timer i'm running a thread
>
> ---
> Thread Status = new Thread(statusJob);
> Status.Start():
> ----

Why are you doing that?  If you need for the timer event to be handled on  
a separate thread, then use Threading.Timer which already runs the timer  
event code on a different thread (it uses a thread pool thread).  Starting  
a whole new thread every time the timer elapses is wasteful and  
unnecessary.

As Peter R. said, you really ought to be more specific about what you're  
doing.  Without describing in detail what timer you're using, how you're  
using it, and what your code does in response to the timer, it's  
impossible to suggest what might be causing the issue you're seeing.

Pete
Peter Ritchie [C# MVP] - 19 Mar 2008 19:45 GMT
It's hard to say what the problem could be with such little to go on.

I agree with Peter though, spawning an new thread on ever Timer tick isn't
the most efficient method.

Signature

Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#

> In the timer i'm running a thread
>
[quoted text clipped - 9 lines]
> > Maybe you can provide some detailed code of what you're doing in your
> > Tick/Elapsed event handlers?
garther - 19 Mar 2008 21:03 GMT
So what method would you suggest for this purpose?

Peter Ritchie [C# MVP] pisze:
> It's hard to say what the problem could be with such little to go on.
>
> I agree with Peter though, spawning an new thread on ever Timer tick isn't
> the most efficient method.
Peter Duniho - 19 Mar 2008 23:35 GMT
> So what method would you suggest for this purpose?

Well, you haven't bothered to answer the questions asked you, including  
"What type of Timer are you using?"  The other relevant question asked but  
not yet answered is "what are you doing in your elapsed event handlers?"

The only thing you've posted so far is code that suggests you're creating  
a whole new thread every time the timer fires.  From what little  
information you've shared so far, it's impossible to tell you exactly how  
to fix that, but it's pretty easy to know that it's almost certainly wrong  
to do it the way you're doing it.

Pete

Rate this thread:







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.