473,602 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Timer / UI thread issue

I have my entire program in a Sub Main class and it runs as a notify tray
icon 99% of the time... inside the program there is a timer whihc is
declared like this

Dim WithEvents MyTimer As New System.Timers.T imer(20000)

the timer checks every 20 seconds a website to pull information from... if a
date is found on the page it looks at, it makes a list of dates and places
them into a date collection declared like this

Dim CurrentDates As New List(Of DateTime)

I also have a "dates form" that will pop up on screen if a date is found.
This is a form that never closes it is only shown and hidden from the
user... now every 20 seconds when the timer "ticks" my web task happens
(cant post code, because of information that is in it) this works perfecly
fine! but when we included the form in the mix, the problems started... the
web part works correctly, but the form is lagging... it will pop up, and
take forever to show the list of dates in its listbox.. then it shows "not
responding" in the titlebar after a second, then after a couple more seconds
it redraws correctly, then it lags again... at one point i was getting
"illegal cross thread.." something or other i forget exceptions when I
opened the form... I tried doing this with delegates but no real changes
that I noticed... here is how I am calling the forms now

when it has to hide

If Me.frmDates.Inv okeRequired Then

Me.frmDates.Inv oke(New HideDateForm(Ad dressOf ProcHideDateFor m))

Else

Me.frmDates.Hid e()

End If

when it has to show

If Me.frmDates.Inv okeRequired Then

Me.frmDates.Inv oke(New ShowDateForm(Ad dressOf ProcShowDateFor m))

Else

Me.frmDates.Sho w()

End If

the delegate declerations

Public Delegate Sub ShowDateForm()

Public Delegate Sub HideDateForm()

Public Delegate Sub SendDatesToForm (ByVal currentDates As List(Of DateTime))

Public Sub ProcShowDateFor m()

Me.frmDates.Sho w()

End Sub

Public Sub ProcHideDateFor m()

Me.frmDates.Hid e()

End Sub

Public Sub ProcSendDatesTo Form(ByVal currentDates As List(Of DateTime))

Me.frmDates.Las tDates = currentDates

End Sub

and the form code

=============== ===========

Imports System.Text.Reg ularExpressions

Public Class frmDates

Private m_lastHTML As New List(Of DateTime)

''' <summary>

''' Last HTML response

''' </summary>

''' <value></value>

''' <returns></returns>

''' <remarks></remarks>

Public Property LastDates() As List(Of DateTime)

Get

Return m_lastHTML

End Get

Set(ByVal value As List(Of DateTime))

m_lastHTML = value

Me.lstDates.Beg inUpdate()

Me.lstDates.Ite ms.Clear()

For Each d As DateTime In LastDates

Me.lstDates.Ite ms.Add(d.ToShor tDateString)

Next

Me.lstDates.End Update()

End Set

End Property


Public Sub New()

' This call is required by the Windows Form Designer.

InitializeCompo nent()

' Add any initialization after the InitializeCompo nent() call.

End Sub

Protected Overrides Sub OnClosing(ByVal e As
System.Componen tModel.CancelEv entArgs)

e.Cancel = True

MyBase.OnClosin g(e)

Me.Hide()

End Sub

End Class

if anyone could PLEASE help me with whats going on i'd really appriciate it,
thanks!
Feb 2 '07 #1
7 1703
"Smokey Grindle" <no****@dontspa mme.comwrote in news:OkNBxtvRHH A.4252
@TK2MSFTNGP05.p hx.gbl:
at one point i was getting
"illegal cross thread.." something or other i forget exceptions when I
opened the form... I tried doing this with delegates but no real changes
that I noticed... here is how I am calling the forms now
Forms are single threaded.

You need to check Invoke the call to the form.

Do a google search on Illegal Cross Thread error and you'll find plenty of
examples.
Feb 2 '07 #2
this code is already based on that though! and when I tried to use delegates
and calling them correctly no change happened in speed

"Spam Catcher" <sp**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"Smokey Grindle" <no****@dontspa mme.comwrote in news:OkNBxtvRHH A.4252
@TK2MSFTNGP05.p hx.gbl:
> at one point i was getting
"illegal cross thread.." something or other i forget exceptions when I
opened the form... I tried doing this with delegates but no real changes
that I noticed... here is how I am calling the forms now

Forms are single threaded.

You need to check Invoke the call to the form.

Do a google search on Illegal Cross Thread error and you'll find plenty of
examples.

Feb 3 '07 #3
"Smokey Grindel" <no****@nospam. comwrote in
news:eU******** *****@TK2MSFTNG P04.phx.gbl:
this code is already based on that though! and when I tried to use
delegates and calling them correctly no change happened in speed
How many dates are you posting to the form?
Feb 3 '07 #4
at most 20... its nothing complex thats why I cant figure out the speed slow
down.... I had a Net.Mail request right after it thought thought it was
causing it took it out and made it Asyncronous and the speed got about 50%
better but still a lag... I havent seen any cross thread errors in a while
though, they seemed to randomly happen even though I am using delegates and
invoking them correctly....

"Spam Catcher" <sp**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"Smokey Grindel" <no****@nospam. comwrote in
news:eU******** *****@TK2MSFTNG P04.phx.gbl:
>this code is already based on that though! and when I tried to use
delegates and calling them correctly no change happened in speed

How many dates are you posting to the form?

Feb 3 '07 #5
"Smokey Grindle" <no****@dontspa mme.comschrieb
I have my entire program in a Sub Main class and it runs as a notify
tray icon 99% of the time... inside the program there is a timer
whihc is declared like this

Dim WithEvents MyTimer As New System.Timers.T imer(20000)

the timer checks every 20 seconds a website to pull information
from... if a date is found on the page it looks at, it makes a list
of dates and places them into a date collection declared like this

Dim CurrentDates As New List(Of DateTime)

[...]
I don't see any problem in your code. One thing that might happen is that
the Form references the same List(Of DateTime) object as the thread (the
Timer thread) that pushes the List into the Form's thread. Maybe this can
lead to none-thread safe operations on the List. I don't know whether the
List is used in the Timer's event handler after Invoke has returned and
simultaneously the Form thread does the same. Though, rather improbable.

Have you tried narrowing the problem down to where the time is spent? Have
you tried logging the time spent in the invoked procedures? How long does
filling the list take? How long does the Invoke call take? And so on. Apart
from the usual debugging that's what I would probably do, but it's hard to
say from here.
Armin

Feb 3 '07 #6
I need to run it through a profiler still, so its on my list of things to
do... I think it happens when the list loads on the form from what I've seen
stepping through the code

"Armin Zingler" <az*******@free net.dewrote in message
news:u2******** ******@TK2MSFTN GP03.phx.gbl...
"Smokey Grindle" <no****@dontspa mme.comschrieb
>I have my entire program in a Sub Main class and it runs as a notify
tray icon 99% of the time... inside the program there is a timer
whihc is declared like this

Dim WithEvents MyTimer As New System.Timers.T imer(20000)

the timer checks every 20 seconds a website to pull information
from... if a date is found on the page it looks at, it makes a list
of dates and places them into a date collection declared like this

Dim CurrentDates As New List(Of DateTime)

[...]

I don't see any problem in your code. One thing that might happen is that
the Form references the same List(Of DateTime) object as the thread (the
Timer thread) that pushes the List into the Form's thread. Maybe this can
lead to none-thread safe operations on the List. I don't know whether the
List is used in the Timer's event handler after Invoke has returned and
simultaneously the Form thread does the same. Though, rather improbable.

Have you tried narrowing the problem down to where the time is spent? Have
you tried logging the time spent in the invoked procedures? How long does
filling the list take? How long does the Invoke call take? And so on.
Apart from the usual debugging that's what I would probably do, but it's
hard to say from here.
Armin

Feb 3 '07 #7
well changed the System.Timers.T imer to System.Windows. Forms.Timer and the
problem disappeared... so definatly think its a cross thread problem....
humm not to figure out why... what is the major difference between the two?
I know Timers.Timer is in its own thread, but will that cause any problems?
the UI thread really does nothing in this program besides show a form with
dates on it sometimes... the only thing doing on was the tick event that
caused the web check... any differences I sould look out for?

"Smokey Grindel" <no****@nospam. comwrote in message
news:u2******** *****@TK2MSFTNG P04.phx.gbl...
>I need to run it through a profiler still, so its on my list of things to
do... I think it happens when the list loads on the form from what I've
seen stepping through the code

"Armin Zingler" <az*******@free net.dewrote in message
news:u2******** ******@TK2MSFTN GP03.phx.gbl...
>"Smokey Grindle" <no****@dontspa mme.comschrieb
>>I have my entire program in a Sub Main class and it runs as a notify
tray icon 99% of the time... inside the program there is a timer
whihc is declared like this

Dim WithEvents MyTimer As New System.Timers.T imer(20000)

the timer checks every 20 seconds a website to pull information
from... if a date is found on the page it looks at, it makes a list
of dates and places them into a date collection declared like this

Dim CurrentDates As New List(Of DateTime)

[...]

I don't see any problem in your code. One thing that might happen is that
the Form references the same List(Of DateTime) object as the thread (the
Timer thread) that pushes the List into the Form's thread. Maybe this can
lead to none-thread safe operations on the List. I don't know whether the
List is used in the Timer's event handler after Invoke has returned and
simultaneous ly the Form thread does the same. Though, rather improbable.

Have you tried narrowing the problem down to where the time is spent?
Have
you tried logging the time spent in the invoked procedures? How long does
filling the list take? How long does the Invoke call take? And so on.
Apart from the usual debugging that's what I would probably do, but it's
hard to say from here.
Armin


Feb 4 '07 #8

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

Similar topics

5
2128
by: Richard P | last post by:
I need some help on timers. My app is asp.net 1.1 website running in a shared hosting environment with a third-party service provider. I currently request and cache 20 - 40 remote RSS feeds. When a user requests the page, the app first tries to retrieve a feed from cache, if the feed has expired, it goes off and request the file from the web. If create a CacheItemRemovedCallback for each item to automatically re-request an expired...
8
2771
by: Daniel P. | last post by:
I'm trying to set a timer that gets called every 3 seconds so I can update a field in the UI with the time elapsed since the process started. What am I doing wrong that timerDF_Tick does not get called? private System.Windows.Forms.Timer timerDF; this.timerDF = new System.Windows.Forms.Timer(this.components);
6
2852
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a TimerState object similar to the example in the System.Threading.Timer documentation. The method which handles the timer events, among other things, periodically calls a method in this TimerState object which raises an event to the startup form,...
9
7858
by: Mark Rae | last post by:
Hi, I've seen several articles about using System Timers in ASP.NET solutions, specifically setting them up in Global.asax' Application_OnStart event. I'm thinking about the scenario where I might need to carry out some back-end processing without pausing the individual users' Session while that process runs. E.g. I might provide the ability for a user to upload a text file of job
8
2718
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a thread to access the database and then displays a modal dialog which allows the user to cancel the task, if it is taking longer than they want, and shows them a display of how long the query has been running so far.
7
5988
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts down the call if the timer event is taking too long to complete...?
5
12204
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
3
3836
by: Beemer Biker | last post by:
Unaccountably, I cannot re-enable a timer from an background thread. The disable works fine, I just cannot get it to start back up. There is no method "InvokeRequired" like there is for windows.forms.controls and I get no error message about cross thread so I am not sure where the problem is. I have a "SerialPoll_timer" that every second requests status from a device on an RS232 port. I use this to determine if the device is on line. ...
8
3363
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location on a network for files and then copies these files to another location (on the network) AND then updates a record in the database. The file copying is performed before the database update because the file system is not transactional. The code...
0
7993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2418
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 we have to send another system
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.